如何禁用javascript中的右键单击?

时间:2013-01-11 04:28:11

标签: javascript javascript-events mouseevent

  

可能重复:
  How do I disable right click on my web page?
  Is right click a Javascript event?

如何禁用右键单击?或者更确切地说,禁用上下文菜单 在那个注意事项上,我如何检测鼠标右键/上键?

这是,以防止人们接受内容或其他任何内容。我正在制作游戏,我也希望能够提供正确的点击。

2 个答案:

答案 0 :(得分:5)

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

但是,某些浏览器阻止禁用和更改上下文菜单,因此它不可靠。

答案 1 :(得分:0)

 <script language="JavaScript">
      <!-- 
      //edit this message to say what you want
      var message="Function Disabled"; 

      function clickIE() {
           if (document.all) {
                alert(message);
                return false;
           }
      }
      function clickNS(e) {
           if(document.layers||(document.getElementById&&!document.all)) {
                if (e.which==2||e.which==3) {
                     alert(message);
                     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");
      }
      // -->
 </script>

检查此网站:

1)http://www.dynamicdrive.com/dynamicindex9/noright.htm

2)http://www.users.totalise.co.uk/~bigoleg/javascript/javascript_disable_right_click.html