posts - 40,  comments - 4,  trackbacks - 0

          <body>標(biāo)簽只有onload\onunload\onbeforeunload事件,而沒有onclose事件。不管頁面是關(guān)閉還是刷新都會執(zhí)行onunload事件。如何捕捉到頁面關(guān)閉呢?
          頁面加載時(shí)只執(zhí)行onload
          頁面關(guān)閉時(shí)只執(zhí)行onunload
          頁面刷新時(shí)先執(zhí)行onbeforeunload,然后onunload,最后onload。這樣我們可以在onbeforeunload中加一個(gè)標(biāo)記,在onunload中判斷該標(biāo)記,即可達(dá)到判斷頁面是否真的關(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 閱讀(2656) 評論(1)  編輯  收藏

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 镇巴县| 惠安县| 勃利县| 石楼县| 方正县| 榕江县| 万源市| 张家口市| 北辰区| 济阳县| 龙陵县| 财经| 双鸭山市| 虞城县| 萨迦县| 志丹县| 安龙县| 西充县| 资兴市| 神木县| 远安县| 海阳市| 阿拉善右旗| 岳阳市| 南丰县| 栾城县| 梁河县| 泰和县| 澄城县| 内乡县| 玛纳斯县| 台江县| 苏尼特右旗| 沙雅县| 莱芜市| 泾阳县| 体育| 容城县| 上高县| 永顺县| 中江县|