JavaScript代码实现禁止右键、禁选择、禁粘贴、禁shift、禁ctrl、禁alt
废话不多说了直接给大家贴代码了。
代码如下:
<scriptlanguage="JavaScript">
<!--
//js禁用某些键的代码
//www.nhooo.com
functionkey(){
if(event.shiftKey){
window.close();}
//禁止Shift
if(event.altKey){
window.close();}
//禁止Alt
if(event.ctrlKey){
window.close();}
//禁止Ctrl
returnfalse;}
document.onkeydown=key;
if(window.Event)
document.captureEvents(Event.MOUSEUP);
functionnocontextmenu(){
event.cancelBubble=true
event.returnValue=false;
returnfalse;}
functionnorightclick(e){
if(window.Event){
if(e.which==2||e.which==3)
returnfalse;}
else
if(event.button==2||event.button==3){
event.cancelBubble=true
event.returnValue=false;
returnfalse;}
}
//禁右键
document.oncontextmenu=nocontextmenu;//forIE5+
document.onmou<ahref="https://www.nhooo.com/article/1141.html"target="_blank"class="infotextkey">sed</a>own=norightclick;//forallothers
//-->
</script>
<bodyonselectstart="returnfalse";onpaste="returnfalse";>
1.oncontextmenu="window.event.returnValue=false"将彻底屏蔽鼠标右键特效
<tableborderoncontextmenu=return(false)><td>no</table>可用于Table
2.<bodyonselectstart="returnfalse">取消选取、防止复制
3.onpaste="returnfalse"不准粘贴
4.oncopy="returnfalse;"oncut="returnfalse;"防止复制
PS:JS防止后退,刷新,关闭的解决办法
<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.0Transitional//EN">
<html><head>
<title>NewDocument</title>
</head>
<scriptlanguage="javascript">
functionRunOnBeforeUnload(){window.onbeforeunload=function(){return'将丢失未保存的数据!';}}
</script>
<bodyonload="RunOnBeforeUnload()">
刷新,关闭,后退,F5测试
</body>
</html>
虽然onbeforeunload这个事件已经Web标准被淘汰,但目前能实现这个效果的也就只有这个事件.还好浏览器都能很好的支持.
测试结果:
IE6.0,FireFox,Chrome通过