Question: How do I test whether my other window is closed or still open?
Let's assume that you opened a new browser window
winRef = window.open( URL, name, features )
Later on, you can check whether this window is still open by using the
if (winRef.closed) alert ("It's closed!")
else alert ("It's still open!")
One problem with the
closed property is that the
winRef window reference itself
may be undefined if the
winRef window is not currently open and has never been opened before.
This situation may cause script errors. To avoid this kind of errors,
your window-opener webpage can initialize
winRef.closed early on,
before all other script code, which would ensure that
winRef.closed is defined at all times.
You can accomplish this by including these statements in the very beginning of your first script block:
winRef = new Object();
winRef.closed = true;
Try this technique using the test below:
How do I open a new browser window?
How do I close a window?
How do I write script-generated content to another window?