Window closed 属性
实例
检查名为 "myWindow" 的窗口是否已关闭的函数:
function checkWin()
{
if (!myWindow) {
document.getElementById("msg").innerHTML = "'myWindow' has never been opened!";
} else {
if (myWindow.closed) {
document.getElementById("msg").innerHTML = "'myWindow' has been closed!";
} else {
document.getElementById("msg").innerHTML = "'myWindow' has not been closed!";
}
}
}
亲自试一试 »
if (!myWindow) {
document.getElementById("msg").innerHTML = "'myWindow' has never been opened!";
} else {
if (myWindow.closed) {
document.getElementById("msg").innerHTML = "'myWindow' has been closed!";
} else {
document.getElementById("msg").innerHTML = "'myWindow' has not been closed!";
}
}
}
定义和用法
closed 属性可返回一个布尔值,该值声明了窗口是否已经关闭。该属性为只读。
当浏览器窗口关闭时,表示该窗口的 Windows 对象并不会消失,它将继续存在,不过它的 closed 属性将设置为 true。
浏览器支持
属性 | |||||
---|---|---|---|---|---|
closed | Yes | Yes | Yes | Yes | Yes |
语法
window.closed
技术细节
返回值: | 布尔值,如果窗口已关闭,则为true;如果窗口已打开,则为false |
---|
❮ Window 对象