Disable Right Button Click On Web Page Using Javascript

Here I am sharing code to disable the right button click on web page .

Some features of this code.

Features:

  • This Javascript code will disable the right mouse click.
  • This will protect  your web site contents from being copied/stealing .
  • Here you can add your message as you want.
  • You can put this javascript code anywhere inside head or body tag of your web page.

 

There are few methods to disabling the right click on web page.

Method 1:

<script type="text/javascript">
   document.onmousedown = disableRightClick;
   var status="Sorry, Right Click is Disabled Here";
   
   function disableRightClick(event) {
      if(event.button == 2) {
           alert(status);
           return false; 
      }
   }
</script>

Method 2:

<script type="text/javascript">
   document.oncontextmenu = document.body.oncontextmenu = function() {
      var status="Sorry, Right Click is Disabled Here"; 
      alert(status);
      return false;
  }
</script>

Method 3:

<script type="text/javascript">
  function disableRightClick(e) {
      e = e || window.event;
      var click = (e.which ? (e.which == 3) : (e.button == 2));
      if (click) {
        var status = "Sorry, Right Click is Disabled Here"; 
        alert(status);
        return false;
      }
  }
  document.onmousedown = disableRightClick;
</script>