About This Product
FontsMadeEasy.com
 
Search This Database:
| Over 5000 Free Fonts | Tutorials | Javascript Forum | Other Javascript Resources | Cheat Sheet
Tutorial archive
General Questions
Javascript 1.2
Navigation
Numbers
Strings
Object Model
Reference Manual
Dialog
Windows
Frames
Forms
Images
Mouse Events
Colors
File Access
Control Status Bar
Dates and Time
Cookies
Client Information
Bookmarklets


Is my window still open?

Question: How do I test whether my other window is still open?

Answer: Let's assume that you opened a new browser window using the window.open() method

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!")
The window.closed property is not supported in Netscape Navigator 2 or Internet Explorer 3. To avoid error messages, you can place the above code within a conditional statement as follows:
if (parseInt(navigator.appVersion>2)) {
 if (winRef.closed) alert ("It's closed!")
 else alert ("It's still open!")
}
(Internet Explorer 3 reports that its version is 2, so the condition involving navigator.appVersion will be true for Navigator 3 and higher and Internet Explorer 4 and higher.)

There is no simple workaround for old browsers. You might want to emulate the window.closed property using the onUnload event handler. However, note that the unload event is not always equivalent to closing the window. For example, this event may occur when the user leaves the original page and goes somewhere else (and the window remains open).

BackBack