window Properties Object Properties Summary
Retrieves whether the referenced window is closed.
HTML |
N/A |
Script |
[ bClosed = ] window.closed |
false |
The window is open. |
true |
The window is closed. |
The property is read-only with a default value of false.
This example opens a named window and shows use of the closed property to check if the window object is closed.
<div align="center"><form>
<input type="button" value="Open window"
onclick="openWin ( )">
<input type="button" value="Check if closed"
onclick="chkIfClosed ( )"></form></div>
<script language="JavaScript">
<!--
function openWin ( ) {
theWin=window.open ( "../sample.html", "theWin",
"height=300,width=500" )
}
function chkIfClosed ( ) {
if ( typeof ( theWin ) =="object" ) {
msg="The window.closed property returns "+
theWin.closed;
if ( theWin.closed ) {
alert ( "As the other window is already closed,
\n the window.closed property returns "+
theWin.closed );
theWin = null;}
else
alert ( "As the other window is still open,
\n the window.closed property returns "+
theWin.closed );
}
else
alert ( "Nothing to do.
Please open the window first." )
}
//-->
</script>
window
close Method, open Method, opener Property