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.

1
  • 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). Commented Jan 11, 2013 at 4:31

2 Answers 2

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

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

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.