Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions




The JavaScript FAQ
Prev Home Next

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 method

winRef = 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). Copyright © 1999-2006, Alexei Kourbatov

The JavaScript FAQ
Prev Home Next

  Mirrored with kind permission of Alexei Kourbatov Design by Interspire