龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > Javascript编程 >

js离开或刷新页面检测(且兼容FF,IE,Chrome)

时间:2014-06-09 10:14来源:网络整理 作者:网络 点击:
分享到:
这篇文章主要介绍了js离开或刷新页面检测(且兼容FF,IE,Chrome)。需要的朋友可以过来参考下,希望对大家有所帮助
代码如下:

<!DOCTYPE html>
<html>
<head>
<script>
  function closeIt()
  {
    return "Any string value here forces a dialog box to \n" +
         "appear before closing the window.";
  }
  window.onbeforeunload = closeIt;
</script>
</head>
<body>
  <a href="http://www.jb51.net">Click here to navigate to
      www.jb51.net</a>
</body>
</html>

兼容FF,IE,Chrome的js离开或刷新页面检测,关键的部分是要有return
精彩图集

赞助商链接