Ask a question »

Disabling right-click on your webpage

November 2015

A simple JavaScript code has been developed to help protect various sources that have been utilised on a designed webpage. All that one needs to do is incorporate the JavaScript code within the head of the HTML document. This code facilitates in disabling the option of right-click on a self designed webpage. For the function 'disableselect (e)' false value is returned and for 'reEnable' true value is returned. In the sub-function of IE4+, a false value is returned for selecting start and context menu within the document. For the sub-function of NS6, fulfilling Windows sidebar option, 'disableselect' function is activated on mouse down and 'reEnable' on mouse click. Finally, closing of copyright option is necessary despite disabling the right-click option for securing the contents of a webpage.

Disabling right-click on your webpage

Often while trying to save some text or pictures from a website, you might wonder why your right-click is not allowed. This is the result of a simple JavaScript code that has been inserted into the website document to prevent copyright infringement issues, or to protect the source of your pictures. If you want to activate this option on your own website, here is a little tutorial on how you can do so, using JavaScript codes.


You should insert the following code in the head of your HTML document, between the <HEAD></HEAD> tags.
<SCRIPT LANGUAGE="JavaScript">  
<!-- Disable  
function disableselect(e){  
return false  

function reEnable(){  
return true  

//if IE4+  
document.onselectstart=new Function ("return false")  
document.oncontextmenu=new Function ("return false")  
//if NS6  
if (window.sidebar){  

You should however note that this procedure is not idiot proof. There are several ways a user can still copy the contents on your website. If they decide to disable the JavaScript on their web browser, they will be able to access your contents, with or without the right-click. Hence, I would strongly suggest you edit the copyright close on your pictures as well as your contents.
For unlimited offline reading, you can download this article for free in PDF format:

See also

In the same category

Published by deri58. - Latest update by Celia Gatward
This document entitled « Disabling right-click on your webpage » from CCM ( is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.