JS防止刷新,后退,关闭

常常会用到的停留页面的操作.兼容IE,FF.代码如下:

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<title> New Document </title>
</head>
<script language="javascript">
function RunOnBeforeUnload() {window.onbeforeunload = function(){ return '将丢失未保存的数据!'; } }
</script>
<body onload="RunOnBeforeUnload()">
刷新,关闭,后退,F5 测试
</body>
</html>

测试结果:

IE6.0,FireFox,Chrome通过

原文地址:https://www.cnblogs.com/yanergui/p/5014298.html