WebDevelopersNotes logo

home-icon Home / HTML / Stopping right clicks by visitors

Stopping right clicks by visitors

Stopping right clicks by visitors

If you want to protect and secure content on your web page, you need to disable right clicking by visitors. When visitors right-click on a web page, they can copy images by selecting the appropriate option from the displayed menu. Here I’ll show you how to prevent right clicks on a web page and thus (?… read note below) protecting and securing the images and content on your web page. We’ll employ JavaScript and write a function that displays an “alert” box when the visitor right-clicks on the page. Try right-clicking on this page.

Put the following code inside the HEAD of your HTML document. This will display an alert when a visitor right-clicks on the page. You can customize the text displayed in the alert box by changing the value of msg variable.

<SCRIPT LANGUAGE="JAVASCRIPT">
<!--
function click(e)
   {
   var msg = "No right click is allowed";
   if (document.all)
      {
      if (event.button == 2)
         {
         alert(msg);
         return false;
         }
      }
   if (document.layers)
      {
      if (e.which == 3)
         {
         alert(msg);
         return false;
         }
      }
   }

if (document.layers)
   {
   document.captureEvents(Event.MOUSEDOWN);
   }

document.onmousedown=click;
//-->
</script>

Click here to see how this works!

Note: This method is not foolproof. A visitor will still be able to save an image if he/she keeps the left mouse pressed and then right-clicks on the page. Also, this method will not work on older browsers or browsers in which JavaScript has been disabled.

Sponsored Links

Your comments
Star icon IMPORTANT Have a question / problem? Click here to ask an expert.

Sponsored Links

Tips

How do I view a deleted web page?
Is there a way to view a deleted web page - one that is no longer available? Yes there is and the solution is quite simple. [more...]

Fact

At Amazon's warehouse, the person (picker) who locates products may walk 10 miles or more in one day. [more...]

We use cookies to give you the best possible website experience. By using WebDevelopersNotes.com, you agree to our Privacy Policy