jquery禁用右鍵、文字選擇功能、複製按鍵的實現
阿新 • • 發佈:2018-12-31
同時適合IE、firefox、谷歌瀏覽器下適用,經過篩選程式碼如下:
Java程式碼
Java程式碼
- //禁用右鍵、文字選擇功能、複製按鍵
- $(document).bind(“contextmenu”,function(){returnfalse;});
- $(document).bind(“selectstart”,function(){returnfalse;});
- $(document).keydown(function(){return key(arguments[0])});
- //按鍵時提示警告
- function key(e){
- var keynum;
- if(window.event){
- keynum = e.keyCode; // IE
- }elseif(e.which){
- keynum = e.which; // Netscape/Firefox/Opera
- }
- if(keynum == 17){
- alert(“禁止複製內容!”);
- returnfalse;
- }
- }
- //禁用右鍵、文字選擇功能、複製按鍵
- $(document).bind("contextmenu",function(){returnfalse;});
- $(document).bind("selectstart",function(){returnfalse;});
- $(document).keydown(function(){return key(arguments[0])});
- //按鍵時提示警告
- function key(e){
- var keynum;
- if(window.event) // IE
- {
- keynum = e.keyCode;
- }
- elseif(e.which) // Netscape/Firefox/Opera
- {
- keynum = e.which;
- }
- if(keynum ==
- }
- <script>
- //遮蔽滑鼠右鍵、Ctrl+N、Shift+F10、F11、F5重新整理、退格鍵
- function document.oncontextmenu(){event.returnValue=false;}//遮蔽滑鼠右鍵
- function window.onhelp(){returnfalse} //遮蔽F1幫助
- function document.onkeydown(){
- if((window.event.altKey)&&
- ((window.event.keyCode==37)|| //遮蔽Alt+方向鍵←
- (window.event.keyCode==39))){ //遮蔽Alt+方向鍵→
- alert("不准你使用ALT+方向鍵前進或後退網頁!");
- event.returnValue=false;
- } if((event.keyCode==8)|| //遮蔽退格刪除鍵
- (event.keyCode==116)|| //遮蔽F5重新整理鍵
- (event.ctrlKey && event.keyCode==82)){ //Ctrl+R
- event.keyCode=0;
- event.returnValue=false;
- }
- if(event.keyCode==122){event.keyCode=0;event.returnValue=false;} //遮蔽F11
- if(event.ctrlKey && event.keyCode==78)event.returnValue=false; //遮蔽Ctrl+n
- if(event.shiftKey && event.keyCode==121)event.returnValue=false; //遮蔽shift+F10
- if(window.event.srcElement.tagName=="A" && window.event.shiftKey)
- window.event.returnValue=false; //遮蔽shift加滑鼠左鍵新開一網頁
- if((window.event.altKey)&&(window.event.keyCode==115)){ //遮蔽Alt+F4
- window.showModelessDialog("about:blank","","dialogWidth:1px;dialogheight:1px");
- returnfalse;
- }
- }
- </script>