May 13, 2000 - The window.closed Property
May 13, 2000|
The window.closed Property
Tips: May 2000
Yehuda Shiran, Ph.D.
windowobject's methods are not consistent in that some of them can be executed even if the window has been closed, while others can't. A typical example for the first type is the
moveTo()method, on the other hand, cannot be executed if the window has been closed. The surest way to check for an open window is to test the
window.closedproperty is a Boolean value that specifies whether a window has been closed. When a window closes, the
windowobject that represents it continues to exist, and its
closedproperty is set to true.
closed to determine whether a window that you opened, and to which you still hold a reference (from the return value of
window.open), is still open. Once a window is closed, you should not attempt to manipulate it. Since
window.closed is only supported by Internet Explorer 4, and Navigator 3, and later, you should account for previous versions. We'll use the following code:
// if win and win.open exist, and win.closed is not true, move the window if (win && win.open && !win.closed) win.moveTo(0, 0);
Internet Explorer 3 and Navigator 2 don't support the
closed property, so it evaluates to
false in a Boolean expression (like any property that doesn't exist, such as
Learn more about windows in Tutorial 1.