Learn how to stop right clicks by visitors to your web pages thus protecting the images displayed and preventing visitors to copy the images and text contents.
stopping right clicks by visitors, preventing image download from web page, protect and secure web page content
Stopping right clicks by visitorsGo to Stopping right clicks by visitorsHTML & JavaScriptGo to HTML and JavaScript tips and tricksTips and tricksGo to web development Tips and tricksHomepage

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>

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.


AddThis Social Bookmark Button


Page contents: Stopping right clicks by visitor to prevent and protect images displayed on a web page.

Page URL: http://www.webdevelopersnotes.com/tips/html/ stopping_right_clicks_by_visitors.php3



Join Mailing List


Feedback/Questions




50+ web hosting FAQs

Search engine for your website

Free software from Google - The Google Pack Collection

Create your own search engine
Search WebDevelopersNotes.com