views:

344

answers:

5

In a web application, sometimes you have popups in the application.

Is it reasonable to when the user closes the main window, close all child popup windows if they are open?

keep in mind the main window will not stay on the same page, the user may navigate to other pages within the same application (meaning even if you keep a reference to all opened child windows, new page requests will loose the reference to opened windows etc).

A: 

You may be able to keep references to the opened child popup windows in a hidden iframe and close them when the iframe detects the browser closing.

Otávio Décio
+5  A: 

Yes I think this is reasonable request.

When you call window.open you can store the handles to the windows returned from this function and then iterate that collection and call close on them when the parent window closes.

Andrew Hare
Yes I can do that, but what happends when they navigate to a different page (main window), those handles are lost but the child window is still open.
Blankman
A: 

There may be security reasons for it - those child windows may retain session information that should be destroyed when the user logs out of the main window. You don't want to expose the user to the danger of having someone else coming along and using their open browser later, and having access to their session.

But from a UI perspective, I agree that its pretty crummy. I think this is a case where its reasonable for an intranet solution, but a bad idea for the Internet.

Spike Williams
A: 

Is this any help? You can always try and pass the array containing all children between pages.

http://www.codeproject.com/KB/scripting/WebChildren.aspx

Chris W
+1  A: 

How about adding some javascript into your popups, that checks for the existance of the parent page every x seconds, and if it's gone to refresh the content with a "session timeout" message. I think you should be able to use the "window.opener.closed" property from the popup to check the parent has been closed... Just a thought.

Zachary