I would like to have a button on a web page with the following behavior:
- The first click opens a popup window.
- For later clicks, if the popup is still open, just bring it to the front. If not, reopen.
The code below works in Firefox (Mac and Windows), Safari (Mac and Windows) and IE8. (I have not tested IE6 or IE7 yet.) However, on Google Chrome (on both Mac and Windows), later clicks did not bring the existing pop-up to the foreground as desired.
How can I make this work in Chrome?
<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>
Background: I am re-asking this question specifically for Google Chrome, since I think my code solves the problem, at least for other modern browsers and IE8. If there is preferred etiquette for this, please let me know.
javascript google-chrome popup
brahn Apr 24 '10 at 5:16 2010-04-24 05:16
source share