Close all popup dialogs when main window closed in ASP.NET
I开发者_运维技巧n my web application a lot of popups opened from the parent window using 'window.open'. So I want to close all those popups when my application's main window is closed. How can I do that?
It's a bit problematic to know that the user closes the window but assuming you do achieve that (by a close button or subscribing to the beforeUnload event) you can close the opened windows by following the next bullets:
- When opening a window, save its
object which is returned from the
window.open
method (preferably to an array so you have all objects in a central place). - When you find out the main window is
closing, execute the
close
method on the saved window objects.
Another possibility:
- Use timer on the opened windows to
check if
opener
is defined (you can try to usetypeof
on a method in the opener page). - When you find out the opener doesn't exist, close the window.
There's no callback
that will notify you that the user closed his browser.
its not possible! You cannot catch browser close event.
You can use model popups to be sure user closed popups before closing the main window.
精彩评论