JavaScript ez 2012-11-05
利用 window 狀態 closed 偵測是否視窗被開啟或關閉了。
a.htm 如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> </head> <body> <span id="MSG"></span> <a href="javascript:void(0)" onclick="test()">開啟</a> <script language="javascript" type="text/javascript"> var obj = null; setInterval(function () { try { if(obj.closed) obj = null; document.getElementById("MSG").innerHTML = "開啟中"; } catch (e) { document.getElementById("MSG").innerHTML = "關閉中"; } }, 1000); function test() { obj = window.open("b.htm"); } </script> </body> </html>
b.htm 如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> </head> <body> 頁面內容 </body> </html>
標籤: JavaScript
本文章網址:
https://www.ez2o.com/Blog/Post/JavaScript-Close-Child-Window
https://www.ez2o.com/Blog/Post/293
https://www.ez2o.com/Blog/Post/JavaScript-Close-Child-Window
https://www.ez2o.com/Blog/Post/293