Checking Before Closing a Window
<HTML>
<HEAD>
<TITLE>window.closed Property</TITLE>
<SCRIPT LANGUAGE="JavaScript">
var newWind;
var isIE3 = (navigator.appVersion.indexOf("MSIE 3") != -1) ? true : false;
function newWindow() {
newWind = window.open("","subwindow","HEIGHT=200,WIDTH=200")
if (newWind.opener == null) {
newWind.opener = window
}
setTimeout("finishNewWindow()", 100)
}
function finishNewWindow() {
var output = ""
output += "<HTML><BODY><H1>A Sub-window</H1>"
output += "<FORM><INPUT TYPE='button' VALUE='Close Main Window'"
output +="onClick='window.opener.close()'></FORM></BODY></HTML>"
newWind.document.write(output)
newWind.document.close()
}
function closeWindow() {
if (isIE3) {
newWind = window.open("","subwindow","HEIGHT=200,WIDTH=200")
}
if (newWind && !newWind.closed) {
newWind.close()
}
}
</SCRIPT>
</HEAD>
<BODY>
<FORM>
<INPUT TYPE="button" VALUE="Open Window" onClick="newWindow()"><BR>
<INPUT TYPE="button" VALUE="Close it if Still Open" onClick="closeWindow()">
</FORM>
</BODY>
</HTML>
Related examples in the same category