spacer
Yehuda Shiran May 13, 2000
The window.closed Property
Tips: May 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

The window object'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 close() method. 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.closed property. The window.closed property is a Boolean value that specifies whether a window has been closed. When a window closes, the window object that represents it continues to exist, and its closed property is set to true.

Use 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 window.tomershiran).

Learn more about windows in Tutorial 1.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business