Forum Moderators: open
I have a script I'm using to open a popup window that displays an extra large image for a product view.
The problem is that if there's another product popup window currently open, you have to click twice before the window will reappear in the front displaying the current product.
Anyone know how I can correct this? Here's my code:
<!--
var newWin;
function openWindow() {
if (newWin && newWin.open &&!newWin.closed)
newWin.focus();
else {
newWin = window.open('http://www.mysite.com/xlimgpopup.html?xlimgurl=(CGIVAR)popup_image_url(/CGIVAR)',[red][b]*[/b][/red]
'XLPopup','width=(CGIVAR)popup_width(/CGIVAR),height=(CGIVAR)popup_height(/CGIVAR),menubar=yes');
}
}
// -->
</SCRIPT>
Thanks!
Note: For some reason this forum script keeps removing the space betweeen && and!newWin.closed, so keep in mind that this is not how my code really looks. There is actually a space there. Thanks
* = line break added to prevent side scroll
[edited by: tedster at 7:21 pm (utc) on Dec. 2, 2006]
newWin.openis required, however, as this will always return true, since it is just testing whether the .open method exists on the window object.
However, by the look of your script... if you click on a different product to what is already shown in the popup window, then it will merely bring the window to the front and not load the new content into the popup window? (Although, are you using some server-side script here?) Since you are already passing the same title ('XLPopup') as the 2nd argument to your window.open() call each time, do you need to test whether the window is already open? And simply call the window.open() and window.focus() methods.... eg:
function alwaysOpenWindow() {
newWin = window.open('/lorem_ipsum.html','XLPopup','width=500,height=500,menubar=yes');
newWin.focus();
}