views:

259

answers:

3

In 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?

A: 

There's no callback that will notify you that the user closed his browser.

Darin Dimitrov
A: 

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:

  1. 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).
  2. When you find out the main window is closing, execute the close method on the saved window objects.

Another possibility:

  1. Use timer on the opened windows to check if opener is defined (you can try to use typeof on a method in the opener page).
  2. When you find out the opener doesn't exist, close the window.
Shay Friedman
A: 

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.

Ozan BAYRAM