JavaScript代码实现禁止右键、禁选择、禁粘贴、禁shift、禁ctrl、禁alt

废话不多说了直接给大家贴代码了。

代码如下:

<script language="JavaScript">
<!--
//js禁用某些键的代码
//www.nhooo.com
function key(){ 
if(event.shiftKey){
window.close();}
//禁止Shift
if(event.altKey){
window.close();}
//禁止Alt
if(event.ctrlKey){
window.close();}
//禁止Ctrl
return false;}
document.onkeydown=key;
if (window.Event)
document.captureEvents(Event.MOUSEUP);
function nocontextmenu(){
event.cancelBubble = true
event.returnValue = false;
return false;}
function norightclick(e){
if (window.Event){
if (e.which == 2 || e.which == 3)
return false;}
else
if (event.button == 2 || event.button == 3){
event.cancelBubble = true
event.returnValue = false;
return false;}
}
//禁右键
document.oncontextmenu = nocontextmenu; // for IE5+
document.onmou<a href="https://www.nhooo.com/article/1141.html" target="_blank" class="infotextkey">sed</a>own = norightclick; // for all others
//-->
</script>

<body onselectstart="return false"; onpaste="return false";>

1. oncontextmenu="window.event.returnValue=false" 将彻底屏蔽鼠标右键特效
<table border oncontextmenu=return(false)><td>no</table> 可用于Table

2. <body onselectstart="return false"> 取消选取、防止复制

3. onpaste="return false" 不准粘贴

4. oncopy="return false;" oncut="return false;" 防止复制

PS:JS防止后退,刷新,关闭的解决办法

<!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>

虽然onbeforeunload这个事件已经Web标准被淘汰,但目前能实现这个效果的也就只有这个事件.还好浏览器都能很好的支持.

测试结果:

IE6.0,FireFox,Chrome通过