Showing posts with label Disable Right Click. Show all posts
Showing posts with label Disable Right Click. Show all posts

Friday, 19 December 2014

Disable Right Click

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>


Summary
In this article I try to expose the disabled and readonly attributes. I hope after reading this article you will be able to use this trick in your code. I would like to have feedback from my blog readers. Please post your feedback, question, or comments about this article.