Disable Right Click

Disable right clicking  in a web browser is very important part in blogging and web-designing in today's world of piracy. It is required whenever we want to stop illegal copying and stealing of contents from webpages. The major use of Right click in a web browser is to copy the images and saving them to local.

The need to disable right click can be understood with the following example:

Think of a image which you have captured or prepared a image with the lot of hard work and want to sell it for some money. To sell it, you have to upload it to a website. After uploading it to the website, it is visible to all visitors. Instead of buying the photo or image, he just copy the photo or image by choosing the option ‘Save as’ from the context menu appeared by right clicking in the web browser. Now all of your hard work is in vain. This is a common example where we need the right click, on a webpage or certain part of webpage, to be disabled.

To avoid the content from being stolen, context menu disabling is required.

 Methods to disable right click context menu:

  1. HTML programming
  2. Using JavaScript.

The second method of using JavaScript to disable right click is not very successful because JavaScript can be disabled in a webpage by changing the settings in the web browser. When JavaScript in your browser is disabled, the code of JavaScript which we are going to use to disable right click, does not works any more and visitor will be able to copy the contents from webpages. Due to this reason, I recommend you to use HTML code to disable right click.

 

Disabling right click with HTML programming:

 Step 1: Find out the following code in the webpage (in case of blog, this can be found in blog template):   

<body>

Step 2: Add the following code in the  angle bracket after body:


onContextMenu="alert('Sorry for inconvenience.\nRight Click is disabled!');return false;"

    in the manner shown below:


<body onContextMenu="alert('Sorry for inconvenience.\nRight Click is disabled!');return false;">

   The code in the ( ) bracket will appear as a message whenever a visitor tries to right click on the webpage. It looks like shown below:


 


2013-10-17 07 06 23



  


In the above code, the text shown in red colour will be shown as message. You can replace it wit your own messages. You can also left it is blank.


‘\n’ is used to create a new line in the message.


For live Demo, visit this blog.


Step 3: Save the template or the webpage. Right click will be disabled now. The above procedure will disable the right clicking on the whole webpage.


You can selectively disable right click for a single element of webpage by inserting the code given in the second step in that element as like the ‘<body>’ (such as  ‘<div>).


Remember to add it in the start tag of the HTML element, not the end tag ( like ‘’)


 


For disabling highlighting the text and images, Visit here


 


Thanks, Have a nice day!


 


LiveJournal Tags:
.


0 comments:

Post a Comment

AddThis

Total Pageviews

Popular Posts

My Blog List