Introduction: Disable right click on web page and images
In this post, we will learn about how to Disable right click on web page and images in asp.net.
In my previous posts I have explained various topics like Nullables in C# Collections in C#SortedSet in C#.Net,Stack in C#,Queue in C#.Net,LinkedList in C#.Net. Now in this post, I will explain about how to disable right click on web page and images.
Many a times it is required to prevent your web page images from being copied by someone else.This is an effective way to prevent your images from being copied or stolen.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;"/>
Disable right click on web page
You 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
I hope you got an idea about Disable right click on web page and images.
I would like to have feedback from my blog readers.
I hope after reading this article you will be able to do this.
Your valuable feedback, question, or comments about this article are always welcome.