如何使用JS拦截并禁止用户复制、剪切、粘贴、鼠标右键(含破解方法)

前言

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

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

如图:

 

 

  • 7
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码上十七

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值