前端坑

使用js禁用浏览器右键菜单,js禁止右击,禁止浏览器菜单,启用了之后还会达到网页内容无法选取的效果

使用js禁用浏览器右键菜单

作者:何兴林 发布时间: 2017-05-16 阅读:


<script>
// js禁止右击,禁止浏览器菜单
// 启用了之后还会达到网页内容无法选取的效果
function click() {
return false;
}
function click1() {
if (event.button==2) { return false; }
}
function CtrlKeyDown(){
if (event.ctrlKey) { return false; }
}
document.onkeydown=CtrlKeyDown;
document.onselectstart=click;
document.onmousedown=click1;
document.oncontextmenu=function(event) {
   if (document.all) 
       window.event.returnValue = false;// for IE
   else 
       event.preventDefault();

</script>

文章地址:http://blog.yunzhancms.com/index.php?s=/Article/detail/id/117 欢迎转载,转载时请注明出处

分享到: