欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

判斷頁面是關(guān)閉還是刷新的js代碼

 更新時(shí)間:2007年01月28日 00:00:00   作者:  
<body>標(biāo)簽只有onload\onunload\onbeforeunload事件,而沒有onclose事件。不管頁面是關(guān)閉還是刷新都會(huì)執(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>
  <title>判斷頁面是關(guān)閉還是刷新</title>
 </head>

 <body onunload="fclose();" onload="fload();" onbeforeunload="bfunload();">
  <script language="javascript">
  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>

相關(guān)文章

最新評論