Window.closed property
Question: How do I test whether my other window is closed or still open?
Answer:
Let's assume that you opened a new browser window
using the winRef = window.open( URL, name, features )Later on, you can check whether this window is still open by using the window.closed property:
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 and 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:
See also:
|
Copyright © 1999-2011, JavaScripter.net.