Please enable Javascript to correctly display the contents on Dot Net Tricks!

Disable right click on web page and images

  Author : Shailendra Chauhan
Updated On : 18 Sep 2012
Total Views : 17,016   
 

Sometimes it is required to prevent your web page images from being copied by another one. You can secure your images by disabling right click or by disabling image context menu on images only. This is an effective approach to prevent your images from being copied or stolen. Here I am going to share the tricks how can you achieve this. This trick will disable right click only on images. Add the below event handler to the img or image tag as shown below:

Disable right click on images

 <asp:Image ID="img1" runat="server" ImageUrl=""../ImgLoc/1.png"" oncontextmenu="return false;" />
<img alt="MyImage" src="../ImgLoc/2.png" oncontextmenu="return false;"/> 

Note

  1. It is impossible to prevent images from being stolen completely since there are so many tools and software through which any one can steal yours images. But something is better than nothing.

Disable right click on web page

Similarly we can disable right click on whole page by adding oncontextmenu handler in body tag of webpage. Now this will disable right click on each and every control of a webpage.
 <html>
<head>
...
</head>
<body oncontextmenu="return false;" >
...
</body>
</html> 

Show alert on right click

 <script type="text/javascript"> 
function disableRightClick() 
{ 
alert("Sorry, right click is not allowed !!"); 
return false; 
} 
</script> 
<body oncontextmenu=" return disableRightClick();">
... 
</body> 
Summary

In this article, I explain how can you disable right click on webpage and images. I hope after reading this article you will be able to do this. I would like to have feedback from my blog readers. Please post your feedback, question, or comments about this article.

YOU MIGHT LIKE
Free Interview Books
 
COMMENTS (0)
14 DEC
ASP.NET MVC with AngularJS Development (online)

MON-FRI 07:30 AM- 09:00 AM IST

Know More
5 DEC
AngularJS Development (online)

Mon - Fri 6:30 AM-7:30 AM IST

Know More
3 DEC
AngularJS Development (offline)

SAT,SUN     11:00 AM-12:30 PM IST

3 DEC
MEAN Stack Development (offline)

Sat, Sun     (09:30 AM-11:00 AM IST)

26 NOV
ASP.NET MVC with AngularJS Development (offline)

(SAT,SUN)     03:30 PM-05:00 PM IST

24 NOV
ASP.NET MVC with AngularJS Development (online)

MON-FRI     09:30 PM-11:00 PM IST

12 NOV
ASP.NET MVC with AngularJS Development (offline)

SAT,SUN     08:00 AM-09:30 AM

3 NOV
ASP.NET MVC with AngularJS Development (online)

MON-FRI     07:30 AM-09:00 AM IST

25 OCT
.NET Development (offline)

Mon-Fri     9:00 AM-11:00 AM IST

BROWSE BY CATEGORY
 
RECENT ARTICLES
SUBSCRIBE TO LATEST NEWS
 
LIKE US ON FACEBOOK
 

Professional Speaks

+