我可以禁用右击在我的网页不使用JavaScript?我问这个问题是因为大多数浏览器允许用户禁用JavaScript。
如果不是,我如何使用JavaScript禁用右键?
我可以禁用右击在我的网页不使用JavaScript?我问这个问题是因为大多数浏览器允许用户禁用JavaScript。
如果不是,我如何使用JavaScript禁用右键?
当前回答
如果你只是想禁用右键保存网页上的图像,请使用以下CSS解决方案:
your-img-tag {
pointer-events: none;
}
在同一映像上实现之前:
在同一映像上实现后:
在Chrome和Firefox中都进行了测试。
其他回答
就这么做
在body标签上写入oncontextmenu
<body oncontextmenu="return false">
使用此功能可以禁用右键操作。你可以禁用左键点击也检查1和0对应
document.onmousedown = rightclickD;
function rightclickD(e)
{
e = e||event;
console.log(e);
if (e.button == 2) {
//alert('Right click disabled!!!');
return false; }
}
将此代码放入页面的<head>标记中。
<script type="text/javascript">
function disableselect(e){
return false
}
function reEnable(){
return true
}
//if IE4+
document.onselectstart=new Function ("return false")
document.oncontextmenu=new Function ("return false")
//if NS6
if (window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable
}
</script>
这将禁用右键点击整个网页,但只有当JavaScript启用。
<script>
window.oncontextmenu = function () {
console.log("Right Click Disabled");
return false;
}
</script>
如果不使用Javascript,您就无法完成您的要求。您可以选择使用的任何其他技术只能帮助在服务器端组成web页面,然后发送到浏览器。
没有好的解决方案,没有Javascript的解决方案周期。