You are here

How to disable right click on images with waring message

Hi Chaps!

Simple script which demonstrates how to disable right clicks on all images on your website/page.

This tutorial is based on jQuery, so first thing We'll do - install it. There are two main methods how to do this;

  1. Upload Jquery library to your sever,
  2. Install Jquery as an external JavaScript.
1. method;
<!-- insert this code between head tags, after all css style-sheets -->
<script type="text/javascript" src="/path-to-jquery/jquery-1.4.4.js"></script> <!--- I am using version 1.4.4 -->

2. method;
<!-- same between head tags -->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js"></script>
...

Now since we've got jQuery installed on the website/page, let's go ahead and write a simple script which will do the job - disable right clicks on all images and give a warning message to site's visitor.

<script type="text/javascript">
$(document).ready(function(){
$('img').bind('contextmenu', function(){
alert("Right clicks are not permitted due to copyright settings");
// more functionality code goes here
return false;
});
});
</script>

Install this small script after main jQuery scripts or right before closing head tag. As you can see disabling default right click functionality on images allows you to add custom code or even create your own right click Context menus, but I'll leave this on your shoulders.