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

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Google Chrome Playing Catch-Up on Extensions
Open Solutions Alliance Gets New Leadership
Red Hat Spacewalk Expands Linux Management
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.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

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

webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags