|
使用 Window 对象的 closed 属性可以判断窗口是否关闭,如果该属性为 ture ,那么表示窗口已经关闭;若该属性为 false ,那么窗口还未关闭。
测试代码:
<html>
<head>
<title>关闭当前窗口</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<script type="text/javascript" language="javascript">
<!--
var myWin;
function openWin() {
myWin = window.open("http://www.groad.net", "onWin");
}
function closeWin() {
if (myWin == undefined) {
alert("no new opened window");
}
else if (myWin.closed) {
alert("window closed");
}
else {
myWin.close();
}
}
-->
</script>
</head>
<body>
<input type="button" onclick="openWin()" value="open a window">
<input type="button" onClick="closeWin()" value="close that window">
</body>
</html>
|
|