0

Possible Duplicate:
How do I disable right click on my web page?
Is right click a Javascript event?

How do I disable the right click? Or rather, disable the context menu.
And on that note, how do I detect right mouse up/down?

This is not to prevent people from taking content or whatever. I'm making a game and I'd like to be able to feature the right click too.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Overcode
  • 4,074
  • 1
  • 21
  • 24
  • 1
    note that some browsers will not let you do this, or let you THINK you've done it and still allow the context menu to appear. (e.g. Firefox). – Marc B Jan 11 '13 at 04:31

2 Answers2

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

However, some browsers prevent disabling and changing the context menu, so it's not reliable.

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
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>

Check this sites:

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

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

Sunil Gulabani
  • 878
  • 1
  • 8
  • 21