TechieDrill Your World Of Technical Tutorials

Disable Mouse Right Click on a Web Page

11.28.2009 · Posted in JavaScript

The following javascript code is used to disable right clicking on a web page.

Disabling Right Click can be a useful way to prevent your users from copying/pasting text on the page. It is thus used as a Security tool.

Here is a simple code to accomplish the same, just paste in the head section of your page.

<SCRIPT language="Text/JavaScript">
 document.onmousedown = HandleClick()
 function HandleClick()
 {
  if ((event.button==2) || (event.button==3)
   alert("Right Click has been disabled!");
 }
</SCRIPT>

Leave a Reply

You must be logged in to post a comment.