计算机/互联网
如何使用JS拦截并禁止用户复制、剪切、粘贴、鼠标右键(含破解方法)
来源:网络     阅读:670
网站管理员
发布于 2023-07-11 23:03
查看主页

前言

想必大家经常会遇到这样的需求,禁止用户复制、剪切、另存为、鼠标右键的操作等。今天一篇文章学会拦截并禁止用户特定操作及破解方法。正所谓道高一尺魔高一丈啊能禁止也能破解


1. 禁止用户选择 达到无法复制的目的

在相关dom标签上给元素onselectstart 赋值为return false


<body onselectstart = "return false" ></body>
或者在script中写类似下面这种代码:
document.onselectstart = function(){
    return false;
}
(阻止事件冒泡:)
document.onselectstart=function(event){
 event.preventDefault();
};


 2. 禁止复制

<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.禁止鼠标右键

<body oncontextmenu = "return false" ></body>

或者


document.oncontextmenu = function(){

    return false;

}

或者


document.onmousedown = function(e){

    if ( e.which === 2 ){ // 鼠标滚轮的按下,滚动不触发

        return false;

    }

    if( e.which === 3  ){// 鼠标右键

        return false;

    }

}

或者


document.oncontextmenu=function(e){

  e.preventDefault();

}

破解方法 

破解方案一: 以谷歌为例,按F12打开调试器,在console.log 控制台输入类似下边代码:


document.onselectstart="";

或者

document.onselectstart=true;


如图:


破解方案二: 设置禁用javascript


以谷歌浏览器为例:


打开调试器,---> 打开设置,--- > 勾选禁用JavaScript





免责声明:本文为用户发表,不代表网站立场,仅供参考,不构成引导等用途。 计算机/互联网 程序设计开发
相关推荐
全屋智能化,白墙配原木,高级又清爽,原来程序员的审美也这么好
程序员如何护肤?
【历程分享】从辣鸡程序员到通过副业如何月入5万
2024年世界互联网大会乌镇峰会亮点集锦
程序员的午餐(附攻略)