PDA

View Full Version : Nested pop-up windows, closing and re-using


ekhoo
10-04-2002, 06:15 AM
Hi,

I've a website that people click on thumbnails of photos to open a pop-up window that will display the photo. This has been working fine, and if they switch back to the main window and click on another photo, the previous pop-up window (if it's not closed) will be re-used. I used window.focus to bring it to the foreground.

Recently, I put in a feature to allow users to add the photo to their favorites list. This works by popping a new popup window with the confirmation. Once they click ok, this window closes. Now, if they go back to the main window and click on another photo, it doesn't re-use the popup, instead, it creates another new window.

In a nutshell:
MainWindow
--> PhotoViewer --> Favorites

When Favorites closes, it becomes:
MainWindow
--> PhotoViewer
--> PhotoViewer
etc.

my window open code is:
function launch(newURL, newName, newFeatures, orgName) {
var remote = open(newURL, newName, newFeatures);
if (remote.open == null)
remote.open = window;
remote.opener.name = orgName;
return remote;
}

How do I make it re-use the PhotoViewer window (if it's open)?

ekhoo
10-04-2002, 07:06 AM
Oops. After asking google and checking javascriptkit, I found a workable solution.

Before I open a new window, I check for the existence of a particular window first.

i.e.
if (!windowname.close)
else

If it's open, I use window.location=url to re-use the window, otherwise, the open code continues and a new window is created.