检测关闭浏览器和屏蔽F5

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
检测浏览器关闭,同时屏蔽F5
listen browser colse event and disable F5,
</body>
</html>
<script type="text/javascript">
<!--
window.onbeforeunload
= onbeforeunload_handler;
window.onunload
= onunload_handler;
document.onkeydown
= disableF5;
function onbeforeunload_handler(){
if(1==1){
var warning="Close this window?";
return warning;
}

}
function onunload_handler(){


}
function disableF5(e)
{

if (!e)
{
var e = window.event;
}
var keycode = e.keyCode;
if (e.which)
keycode
= e.which;

var src = e.srcElement;
if (e.target)
{
src
= e.target;
}
// 116 = F5
if (116== keycode)
{
// Firefox and other non IE browsers
if (e.preventDefault)
{
e.preventDefault();
e.stopPropagation();
}
// Internet Explorer
elseif (e.keyCode)
{
e.keyCode
=0;
e.returnValue
=false;
e.cancelBubble
=true;
}

returnfalse;
}
}

-->
</script>

IE6 不行 :(

原文地址:https://www.cnblogs.com/whoknows/p/2243299.html