复制代码 代码如下:
<!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="//www.jb51.net">Click here to navigate to
www.jb51.net</a>
</body>
</html>
兼容FF,IE,Chrome的js离开或刷新页面检测,关键的部分是要有return
您可能感兴趣的文章:
- javascript中SetInterval与setTimeout的定时器用法
- 深入探寻javascript定时器
- node.js中的定时器nextTick()和setImmediate()区别分析
- 解决微信浏览器Javascript无法使用window.location.reload()刷新页面
- js禁止页面刷新与后退的方法
- javascript关于open.window子页面执行完成后刷新父页面的问题分析
- js获取当前时间显示在页面上并每秒刷新
- 刷新页面的几种方法小结(JS,ASP.NET)
- JS刷新当前页面的几种方法总结
- JavaScript实现页面定时刷新(定时器,meta)