pTutorial

New way to learn Programming

How To Disable Right Click JavaScript

how to disable right click

You can disable right click by using HTML attribute (Which is actually javaScript event handler) and javaScript also. Here are the example below.

Right click disable JavaScript

<script>
    document.onmousedown=disableclick;
    status="Right Click Disabled";
    function disableclick(event)
    {
      if(event.button==2)
       {
         alert(status);
         return false;    
       }
    }
    </script>

and

    <body oncontextmenu="return false">
    ...
    </body>

Explanation

Put the JavaScript code inside the head tag and oncontextmenu in the body tag.

See Also


QUOTES OF THE DAY

Everything flows, nothing stays still.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER