Forum Moderators: open

Message Too Old, No Replies

Problem with window.open

         

kelly5518

2:18 pm on Nov 26, 2006 (gmt 0)

10+ Year Member



Hi,

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]

eelixduppy

7:06 pm on Dec 2, 2006 (gmt 0)



Check for javascript errors produced by your browser(javascript console, error alerts, etc...)

penders

5:27 pm on Dec 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Your script does seem to work OK (FF and IE)... in that it will bring an already open window to the front again, on a single click. No JS errors in the script you have given as far as I can tell. I question whether
newWin.open
is 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();
}