Related Posts Plugin for WordPress, Blogger...

About

Follow Us

Thursday, 26 February 2015

We can prevent Images from being downloaded on our website. I f we want to protect our images then this is necessary to avoid right option on the images.

In this article I am going to share two ways to prevent the right click only on specific images or all images rather than all the contents(text  and images) in asp.net web page using jQuery to avoid/protect the images from being downloaded.


Disabling right click on images may be required if we don’t want to allow the user to copy the images from the page.

Implementation: I have explained two methods to prevent right click on images. Let’s create a sample web page to demonstrate the concept by both methods.

Disable Right Click on All Images
First Way:
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Disable right click on images on asp.net web page using jQuery</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $('img').on("contextmenu", function () {
                return false;
            });
        });
</script>
</head>
<body>
    <form id="form1" runat="server">
    <fieldset style="width:300px;">
    <legend><strong>Disable right Click On Images </strong></legend>
    <br />
   <div >

        In this article I am going to share two ways to prevent the right click only on specific images or all images rather than all the contents(text  and images) in asp.net web page using jQuery to avoid/protect the images from being downloaded.
          <br />
         <br />
       <img src="a7a7a251ce5e187543a75b09.jpg" />
        
    </div>
    </fieldset>
    </form>
</body>
</html>

Second Way:
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Disable right click on images on asp.net web page using jQuery</title>
  
       <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
   <script type="text/javascript">
       $(function () {
           $('img').on("contextmenu", function (event) {
               event.preventDefault();
           });
       });
</script>

</head>
<body>
    <form id="form1" runat="server">
    <fieldset style="width:300px;">
    <legend><strong>Disable right Click On Images </strong></legend>
    <br />
   <div >

        In this article I am going to share two ways to prevent the right click only on specific images or all images rather than all the contents(text  and images) in asp.net web page using jQuery to avoid/protect the images from being downloaded.
          <br />
         <br />

       <img src="a7a7a251ce5e187543a75b09.jpg" />
        
    </div>
    </fieldset>
    </form>
</body>
</html>


Disable Right Click on specific image
In the above example, we disable right click on each image in the page. If we want to disable right click on only specific image then we need to assign id to the img tag as highlighted below:
<img id="myImg"  src="a7a7a251ce5e187543a75b09.jpg" />

Replace the jQuery function with following Function:
    <script type="text/javascript">
     $(function () {
            $('#myImg').on("contextmenu", function () {
                return false;
            });
        });

</script>



Now right click will be disabled on images,  but it will work on text content.

Categories: ,

0 comments:

Post a Comment