检查新窗口是否被关闭
- <!DOCTYPE html>
- <html>
- <head>
-
- <script>
- var myWindow;
- function openWin() {
- myWindow = window.open("", "", "width=400 ,height=200");
- }
-
- function closeWin() {
- if (myWindow) {
- myWindow.close();
- }
- }
-
- function checkWin() {
- msg = ""
- if (!myWindow) {
- msg = "从未打开";
- } else {
- if (myWindow.closed) {
- msg = "已关闭";
- } else {
- msg = "已打开";
- }
-
- }
- document.getElementById("msg").innerHTML =
- "myWindow " + msg;
- }
- </script>
-
- </head>
- <body>
-
- <button onclick="openWin()">打开 myWindow</button>
- <button onclick="closeWin()">关闭 myWindow</button>
- <button onclick="checkWin()">myWindow 打开了吗?</button>
-
- <br><br>
- <div id="msg"></div>
-
- </body>
- </html>