Heim > Artikel > Web-Frontend > 基于jquery的禁用右键、文本选择功能、复制按键的实现代码_jquery
同时适合IE、firefox、谷歌浏览器下适用,经过筛选代码如下:
//按键时提示警告
function key(e){
var keynum;
if(window.event){
keynum = e.keyCode; // IE
}else if(e.which){
keynum = e.which; // Netscape/Firefox/Opera
}
if(keynum == 17){
alert(“禁止复制内容!”);
return false;
}
}
//禁用右键、文本选择功能、复制按键
$(document).bind("contextmenu",function(){return false;});
$(document).bind("selectstart",function(){return false;});
$(document).keydown(function(){return key(arguments[0])});
//按键时提示警告
function key(e){
var keynum;
if(window.event) // IE
{
keynum = e.keyCode;
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e.which;
}
if(keynum == 17){ alert("禁止复制内容!");return false;}
}
<script> <BR>//屏蔽鼠标右键、Ctrl+N、Shift+F10、F11、F5刷新、退格键 <BR>function document.oncontextmenu(){event.returnValue=false;}//屏蔽鼠标右键 <BR>function window.onhelp(){return false} //屏蔽F1帮助 <BR>function document.onkeydown(){ <BR> if((window.event.altKey)&& <BR> ((window.event.keyCode==37)|| //屏蔽Alt+方向键← <BR> (window.event.keyCode==39))){ //屏蔽Alt+方向键→<BR> alert("不准你使用ALT+方向键前进或后退网页!"); <BR> event.returnValue=false; <BR> } if((event.keyCode==8)|| //屏蔽退格删除键 <BR> (event.keyCode==116)|| //屏蔽F5刷新键 <BR> (event.ctrlKey && event.keyCode==82)){ //Ctrl+R <BR> event.keyCode=0; <BR> event.returnValue=false; <BR> } <BR> if(event.keyCode==122){event.keyCode=0;event.returnValue=false;} //屏蔽F11 <BR> if(event.ctrlKey && event.keyCode==78)event.returnValue=false; //屏蔽Ctrl+n <BR> if(event.shiftKey && event.keyCode==121)event.returnValue=false; //屏蔽shift+F10 <BR> if(window.event.srcElement.tagName=="A" && window.event.shiftKey) <BR> window.event.returnValue=false; //屏蔽shift加鼠标左键新开一网页 <BR> if((window.event.altKey)&&(window.event.keyCode==115)){ //屏蔽Alt+F4 <BR> window.showModelessDialog("about:blank","","dialogWidth:1px;dialogheight:1px"); <BR> return false; <BR> } <BR> } <BR></script>