Please disable your adblock and script blockers to view this page
 

jQuery to disable or prevent right click on asp.net web page to protect HTML Source or images from being copied

IntroductionIn this article I am going to share two ways to prevent the mouse right click on asp.net web page using jQuery to avoid/protect the images from being copied or preventing HTML Source code of the page from being seen.

In previous articles i explained how to Disable mouse right click on images only in asp.net web page using jquery and Disable Right click on asp.net website page using JavaScript and jQuery to calculate Running Total of Textbox values and jQuery AJAX JSON example to call Asp.net server side function without any post back and Implement Jquery form validations in asp.net and jQuery to limit and display number of characters left in multiline textbox 

Description: Disabling right click on page may be required in the following scenarios
  • We don’t want to allow the user to view the HTML Source of the page.
  • We don’t want to allow the user to copy the images from the page.
  • We don’t want to allow the user to paste directly in form’s input controls (for example preventing users to paste anything in contact us or feedback form rather than manually filling the form)

Implementation: I have presented two ways to prevent right click on web page.We can use any of the two to achieve our target. Let’s create a sample web page to demonstrate the concept by both methods.

First Way:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
        <title>Disable right click on 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 () {
            $(this).on("contextmenu", function () {
                return false;
            });
        });
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        This is dummy text<br />
        This is dummy text<br />
        This is dummy text<br />
        This is dummy text<br />
        This is dummy text<br />
    </div>
    </form>
</body>
</html>

Second Way:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Disable right click on 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 () {
            $(this).on("contextmenu", function (event) {
                event.preventDefault();
            });
        }); 
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        This is dummy text<br />
        This is dummy text<br />
        This is dummy text<br />
        This is dummy text<br />
        This is dummy text<br />
    </div>
    </form>
</body>
</html>

Now run the page and try to right click on it.You will not be able to right click on the page.

Now over to you:
" I hope you have got the solution to prevent right click on asp.net web page using jquery and If you like my work; you can appreciate by leaving your comments, hitting Facebook like button, following on Google+, Twitter, Linked in and Pinterest, stumbling my posts on stumble upon and subscribing for receiving free updates directly to your inbox . Stay tuned and stay connected for more technical updates." 
Previous
Next Post »

If you have any question about any post, Feel free to ask.You can simply drop a comment below post or contact via Contact Us form. Your feedback and suggestions will be highly appreciated. Also try to leave comments from your account not from the anonymous account so that i can respond to you easily.. ConversionConversion EmoticonEmoticon