html5中文学习网

您的位置: 首页 > 网站及特效实例 > javascript特效 » 正文

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

[ ] 已经帮助:人解决问题
复制代码 代码如下:

<!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
(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助