javascript - 右键单击禁用不适用于滚动按钮单击,它显示警报但在新选项卡中打开
问题描述
我正在为我的网站禁用右键单击,但是当我使用鼠标并单击滚动按钮时,它会显示警报,然后单击确定后它会在新选项卡中打开。我怎样才能禁用它?下面是我的 Javascript 代码。请帮帮我。
// Right Click Disable Functions starts here
function clickIE()
{
if (document.all)
{
alert("Right click is disabled for Security Reasons.");
return false;
}
}
function clickNS(e)
{
if(document.layers||(document.getElementById&&!document.all))
{
if (e.which==2||e.which==3)
{
alert("Right click is disabled for Security Reasons.");
return false;
}
}
}
if (document.layers)
{
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS;
}
else
{
document.onmouseup=clickNS;document.oncontextmenu=clickIE;
}
document.oncontextmenu=new Function("return false")
// Right Click Disable Functions Ends here
解决方案
mouseup事件在mousedown事件之后触发。您需要的是防止mousedown事件(用于右键和中键)。所以你只需要使用document.onmousedown insted of document.onmouseup。
推荐阅读
- c# - 如何从 ASP.Net Web API 中的 SQL 表中获取嵌套的 JSON 对象
- python-3.x - 开始远离 y 轴的线图
- php - curl 不起作用并且无法显示 print_r 数据
- c# - 正则表达式 - 仅当另一个命名组匹配时命名组
- mongodb - NestJS Mongoose 连接在负载测试时终止
- spring-rabbit - 我需要在配置文件中添加任何其他内容吗?
- javascript - 如何使用 Vue.js 方法设置数据属性
- cmake - 在 Rust 上链接 C++:对 `operator delete(void*)' 和 `__gxx_personality_v0' 的未定义引用,缺少 libstdc++?
- python - 使用 tf.scatter_nd 使 Keras 'None' 批量大小不变
- python - 当列有多个选择时,如何计算数据透视表中的行百分比 - 使用 python pandas