JS 禁止刷新和右键

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head> <body>
<div style="width:100px; height:100px; background:#09C;"
</body>
<script type="text/javascript">
//F5
document.documentElement.onkeydown=function(e){
e=e||window.event;
if(e.keyCode==116){
if(e.returnValue){
e.returnValue=false;
}else{
e.stopPropagation();
}
return false;
}
}
//右键
document.documentElement.oncontextmenu=function(e){
e=e||window.event;
e.cancelBubble = true;
e.returnValue=false;
return false;
}
</script>
</html>

没有测试

已经测试了的

/**--  禁止F5刷新 针对IE --**/
document.onkeydown = function()
{
/*
(ctrlKey == true && keyCode == 82) Ctrl+R ---刷新
(keyCode == 116) F5 ---刷新
(ctrlKey == true && keyCode == 116) Ctrl+F5 ---强制刷新
*/
//alert(event.keyCode);
var k = event.keyCode;
if((event.ctrlKey == true && k == 82) || (k == 116) || (event.ctrlKey == true && k == 116))
{
//return (window.confirm("关闭?"));
event.keyCode = 0;
event.returnValue = false;
event.cancelBubble = true;
}
}

禁止鼠标右键

<body onselectstart="return false">
上一篇:js实现禁止右键 禁止f12 查看源代码


下一篇:用JS实现控制浏览器F12与右键功能