当前位置:asp编程网>技术教程>Javascript教程>  正文

屏蔽右键代码兼容IE,google,firefox,opera等常见浏览器

2018-01-11 10:34:00   来源:网络   作者:佚名   浏览量:3291   收藏

网上找了这么多屏蔽页面上右键代码,都不能完全兼容所有浏览器,我将几个代码综合了一下,实现了兼容IE,google,firefox,opera等常见浏览器的屏蔽右键的代码,代码如下,请按注释要求放到页面相应的地方即可


以下这段代码放到<head></head>中,这段代码主要用来屏蔽除火狐浏览器外的浏览器右键代码

<script>

//禁止右键

if (window.Event){

   document.captureEvents(Event.MOUSEUP);

}

function nocontextmenu(){

   event.cancelBubble = true

   event.returnValue = false;

   return false;

}

function norightclick(e) {

   if (window.Event) {

       if (e.which == 2 || e.which == 3)

           return false;

   } else if (event.button == 2 || event.button == 3){

       event.cancelBubble = true

       event.returnValue = false;

       return false;

   }

}

document.oncontextmenu = nocontextmenu; // for IE5+

document.onmousedown = norightclick; // for all others

</script>


以下代码放到页面<body></body>中,这段主要屏蔽火狐浏览器右键代码

<script>

   document.oncontextmenu = function(){return false;};

</script>


关于我们-广告合作-联系我们-积分规则-网站地图

Copyright(C)2013-2017版权所属asp编程网