Disable right click on the website

Many developers/website owners like to keep their website images personal and don't want anyone to copy it from their website.

In order to accomplish this place the following java script code in between the <head>  </head> tag of your master page:

<script type="text/javascript">
  
var message = "Sorry, Right Clicks have been disabled"; // Message for the alert box
  
                   // Don't edit below!
  
                   function click(e) {
                       if (document.all) {
                           if (event.button == 2 || event.button == 3) {
                               alert(message);
                               return false;
                           }
                       }
                       else {
                           if (e.button == 2 || e.button == 3) {
                               e.preventDefault();
                               e.stopPropagation();
                               alert(message);
                               return false;
                           }
                       }
                   }
                   if (document.all) {
                       document.onmousedown = click;
                   }
                   else {
                       document.onclick = click;
                   }
           </script>


P.S. Just by disabling the right click doesn't stop anyone from downloading or copying from any website as there are many other ways to do that.

About Author

Written By Lavish Kumar

Based out of New York, USA, Lavish Kumar is a full stack web developer by profession and founder of Striving Programmers, a trusted community for developers that offers a wealth of articles and forums to assist individuals with improving their software development skills.

Related Blog Posts
Leave your comment