JavaScript 参考手册
Window closed 属性
检测新窗口"myWindow" 是否已被关闭
源代码:
点击运行 »
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>蜜蜂教程(mifengjc.com)</title> <script> var myWindow; function openWin() { myWindow = window.open("", "", "width=400,height=200"); } function closeWin() { if (myWindow) { myWindow.close(); } } function checkWin() { if (!myWindow) { document.getElementById("msg").innerHTML = "我的窗口没有被打开!"; } else { if (myWindow.closed) { document.getElementById("msg").innerHTML = "我的窗口被关闭!"; } else { document.getElementById("msg").innerHTML = "我的窗口没有被关闭!"; } } } </script> </head> <body> <input type="button" value="打开我的窗口" onclick="openWin()" /> <input type="button" value="关闭我的窗口" onclick="closeWin()" /> <br><br> <input type="button" value="我的窗口被关闭了吗?" onclick="checkWin()" /> <br><br> <div id="msg"></div> </body> </html>
运行结果:
点击运行 »