Advertisements
Home > ASP.NET > Disable right click on web page and images

Disable right click on web page and images


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 : 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>

 


 

Hope it helps!

Advertisements
Categories: ASP.NET
  1. December 11, 2015 at 11:04 am

    I just like the valuable information you supply in your articles.
    I’ll bookmark your blog and take a look at again right here frequently.
    I’m quite sure I will be informed many new stuff right here!
    Good luck for the next!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: