posts - 40,  comments - 4,  trackbacks - 0

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

          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
          <title>新建網(wǎng)頁 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('這是關(guān)閉頁面');
          }

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

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

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

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


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 麻栗坡县| 台山市| 大渡口区| 嘉鱼县| 大石桥市| 社会| 汉源县| 公主岭市| 闽侯县| 吉首市| 安仁县| 重庆市| 陆良县| 民乐县| 仁布县| 巫山县| 南靖县| 来安县| 前郭尔| 蒙自县| 广昌县| 探索| 筠连县| 德惠市| 洛扎县| 萍乡市| 白朗县| 中牟县| 乐都县| 乌兰察布市| 保德县| 郴州市| 绥江县| 宣化县| 阿巴嘎旗| 广东省| 习水县| 千阳县| 拉孜县| 吴旗县| 石棉县|