Update: This hasn't worked since Chrome (21+). The workaround is to close/reopen.
The following code works for me on Firefox (Mac & Windows), Safari (Mac & Windows), and IE8 (Windows, of course). I haven't tested IE6 or IE7.
However, it does not work on Chrome for either Mac or Windows. Specifically, clicking the button once creates the pop-up and brings it to the front. However, returning to the original window and clicking the button again does not refocus the popup.
<head>
<script type="text/javascript">
var popupWindow = null;
var doPopup = function () {
if (popupWindow && !popupWindow.closed) {
popupWindow.focus();
} else {
popupWindow = window.open("http://google.com", "_blank",
"width=200,height=200");
}
};
</script>
</head>
<body>
<button onclick="doPopup(); return false">
create a pop-up
</button>
</body>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…