Click to See Complete Forum and Search --> : Detecting if window exists


Ryan
11-29-2002, 08:57 PM
is there a way to detect if a window exists with javascript?

i need to execute a function when a certain window has been closed.

thanks in advance

gil davis
11-30-2002, 12:13 AM
You can only detect a window if:
1) you know the name of the window, or
2) you have a pointer to the window because you opened it, or
3) you are in a child window and you want to know about your opener.

Even if you know the name, you still need a pointer. You can get a pointer to a window called "theName" using:

var myWin = window.open("", "theName");

Unfortunately, if the window does not exist, this will open a new empty window.

Once you have a pointer, you can test if the window is closed:

if (myWin.closed) ...