posts - 40,  comments - 4,  trackbacks - 0

          <body>標簽只有onload\onunload\onbeforeunload事件,而沒有onclose事件。不管頁面是關閉還是刷新都會執行onunload事件。如何捕捉到頁面關閉呢?
          頁面加載時只執行onload
          頁面關閉時只執行onunload
          頁面刷新時先執行onbeforeunload,然后onunload,最后onload。這樣我們可以在onbeforeunload中加一個標記,在onunload中判斷該標記,即可達到判斷頁面是否真的關閉了。
          <html>

          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
          <title>新建網頁 1</title>
          </head>

          <body onunload=fclose() onload=fload() onbeforeunload=bfunload()>
          <script>
          var s = "test";
          function fclose()
          {
          ?? if(s=="no")
          ????? alert('unload me!='+s+'這是刷新頁面!');
          ?? else
          ????? alert('這是關閉頁面');
          }

          function fload()
          {
          ?? alert("load me!="+s);
          }

          function bfunload()
          {
          ?? s = "no";
          }
          </script>
          </body>
          </html>

          posted on 2006-08-09 14:59 larryjava 閱讀(2650) 評論(1)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 旬阳县| 德庆县| 金阳县| 张家港市| 阳原县| 公主岭市| 明溪县| 勃利县| 甘南县| 石泉县| 城口县| 嫩江县| 雷波县| 肥东县| 卓尼县| 漳州市| 玛多县| 通河县| 苍溪县| 镇原县| 怀宁县| 武汉市| 宝兴县| 海安县| 麻城市| 双柏县| 灵台县| 东城区| 凤城市| 阜平县| 准格尔旗| 保康县| 青川县| 西昌市| 雅江县| 汕尾市| 安图县| 科技| 麻栗坡县| 巩义市| 离岛区|