解除网站禁用右键 解除禁用选择方法 并允许复制

限制我复制,太恶心了,别用技术作恶!!!

一般HTML网站禁止右键选择的方法

<body ondragstart="return false" oncontextmenu="return false" onselectstart="return false">

解除网站禁用右键方法 并允许复制

有的网页禁止了鼠标右键,无法查看源代码,解锁很简单 :将常见的 document 事件处理程序全部设为 null,这可以解除大部分网站对鼠标、键盘和触控的限制。

以谷歌浏览器(Chrome)为例:

一、同时按下 ctrl+shft+i 键,打开检查元素项。如果页面禁止键盘,点击浏览器右上角三个点 - 更多工具(More tools) - 开发人员工具(Developer tools)
二、在打开的开发人员工具中,
  1. 选择【源代码(Source)】
  2. 选择【内容脚本(Snippets)】
  3. 新增 Javascript 脚本
  4. 将以下代码粘贴到右侧窗体中
  5. 点击右下角的 Ctrl+Enter 执行上述脚本,就可以解除网页被禁止的鼠标右键了。
// 鼠标事件
document.oncontextmenu = null;  // 解除鼠标右键
document.onselectstart = null;  // 解除文字选择
document.onmousedown = null;    // 解除鼠标按下事件
document.onmouseup = null;      // 解除鼠标释放事件
document.onclick = null;        // 解除鼠标点击事件
document.ondblclick = null;     // 解除鼠标双击事件
document.onmousemove = null;    // 解除鼠标移动事件
document.onmouseover = null;    // 解除鼠标悬浮事件
document.onmouseout = null;     // 解除鼠标移出事件
document.onmouseenter = null;   // 解除鼠标进入事件
document.onmouseleave = null;   // 解除鼠标离开事件

// 键盘事件
document.onkeydown = null;      // 解除按下键盘按键事件
document.onkeyup = null;        // 解除键盘按键释放事件
document.onkeypress = null;     // 解除键盘按键按下和释放事件

// 触摸事件(移动端)
document.ontouchstart = null;   // 解除手指按下事件
document.ontouchmove = null;    // 解除手指滑动事件
document.ontouchend = null;     // 解除手指释放事件
document.ontouchcancel = null;  // 解除触摸取消事件

// 滚动事件
document.onscroll = null;       // 解除滚动事件

// 拖放事件
document.ondrag = null;         // 解除拖动事件
document.ondragstart = null;    // 解除拖动开始事件
document.ondragend = null;      // 解除拖动结束事件
document.ondragenter = null;    // 解除拖动进入事件
document.ondragleave = null;    // 解除拖动离开事件
document.ondragover = null;     // 解除拖动悬浮事件
document.ondrop = null;         // 解除拖放事件
document.oncopy = null;         // 解除复制事件
document.oncut = null;          // 解除剪切事件
document.onpaste = null;        // 解除粘贴事件

// 禁用用户选择样式(如禁用选中文字)
document.body.style.userSelect = 'auto';

document.title = '禁止鼠标右键已解除';
alert(document.title);

在这里插入图片描述

或者用for循环 将所有document事件设为null

// 常见事件属性名称
const events = [
    'oncontextmenu', 'onselectstart', 'onmousedown', 'onmouseup', 'onclick', 'ondblclick',
    'onmousemove', 'onmouseover', 'onmouseout', 'onmouseenter', 'onmouseleave', 'onkeydown',
    'onkeyup', 'onkeypress', 'ontouchstart', 'ontouchmove', 'ontouchend', 'ontouchcancel',
    'onscroll', 'ondrag', 'ondragstart', 'ondragend', 'ondragenter', 'ondragleave', 
    'ondragover', 'ondrop', 'oncopy', 'oncut', 'onpaste'
];

// 遍历并解除所有指定的事件
events.forEach(event => {
    document[event] = null;
});

// 解除用户选择禁用样式
document.body.style.userSelect = 'auto';

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

小黄人软件

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

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

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

打赏作者

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

抵扣说明:

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

余额充值