前言
想必大家經(jīng)常會遇到這樣的需求,禁止用戶復(fù)制、剪切、另存為、鼠標(biāo)右鍵的操作等。今天一篇文章學(xué)會攔截并禁止用戶特定操作及破解方法。正所謂道高一尺魔高一丈啊能禁止也能破解
1. 禁止用戶選擇 達(dá)到無法復(fù)制的目的
在相關(guān)dom標(biāo)簽上給元素onselectstart 賦值為return false
<body onselectstart = "return false" ></body>
或者在script中寫類似下面這種代碼:
document.onselectstart = function(){
return false;
}
(阻止事件冒泡:)
document.onselectstart=function(event){
event.preventDefault();
};
?2. 禁止復(fù)制
<body oncopy = "return false" ></body>
或者?
document.oncopy = function(){
return false;
}
或者?
document.oncopy=function(e){
e.preventDefault();
}
3.禁止剪切
<body oncut = "return false" ></body>
或者
document.oncut = function(){
return false;
}
或者
document.oncut=function(e){
e.preventDefault();
}
?4.屏蔽粘貼
<body onpaste= "return false" ></body>
或者
document.onpaste= function(){
return false;
}
或者
document.onpaste=function(e){
e.preventDefault();
}
5.禁止鼠標(biāo)右鍵
<body oncontextmenu = "return false" ></body>
或者
document.oncontextmenu = function(){
return false;
}
或者
document.onmousedown = function(e){
if ( e.which === 2 ){ // 鼠標(biāo)滾輪的按下,滾動不觸發(fā)
return false;
}
if( e.which === 3 ){// 鼠標(biāo)右鍵
return false;
}
}
或者
document.oncontextmenu=function(e){
e.preventDefault();
}
破解方法?
破解方案一: 以谷歌為例,按F12打開調(diào)試器,在console.log 控制臺輸入類似下邊代碼:
document.onselectstart="";
或者
document.onselectstart=true;
如圖:
破解方案二: 設(shè)置禁用javascript
以谷歌瀏覽器為例:
打開調(diào)試器,---> 打開設(shè)置,--- > 勾選禁用JavaScript
如圖:
?文章來源:http://www.zghlxwxcb.cn/news/detail-526114.html
?文章來源地址http://www.zghlxwxcb.cn/news/detail-526114.html
到了這里,關(guān)于如何使用JS攔截并禁止用戶復(fù)制、剪切、粘貼、鼠標(biāo)右鍵(含破解方法)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!