Easiest way to Disable mouse right click using Javascript - Free Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server,WCF,Entity framework snippets and tutorial

Easiest way to Disable mouse right click using Javascript

In this article today I am going to explain easiest way to disable mouse right click using Javascript

Description:

Sometimes we need to disable the mouse right click to protect the content/images. I have an page and want to disable the right click on it. Add the below given script in head section of page.
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
    <script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
  <script type="text/javascript">
        $(document).bind("contextmenu", function (e) {
            e.preventDefault();
        });
</script>

If you want to show message on right click so add the below given script.
  <script type="text/javascript">
        $(document).bind("contextmenu", function (e) {
            e.preventDefault();
            alert("Right Click is disabled!!!");
        });
</script>

Run the project and check the result.


Note: Right click disable does not protect the content of the website. User can check the page source (Control+U) or can disable the Javascript.

Demo:
Easiest way to Disable mouse right click using Javascript


  In this article we have learn easiest way to disable the mouse right click using Javascript in Asp.net(C#, VB). I hope you enjoyed this article. 

What do you think about this article?

If you found this article useful, please share and follow on Facebook, Twitter, Google Plus and other social media websites. To get free updates subscribe to newsletter. Please put your thoughts and feedback in comments section.

Share this

Share on FacebookTweet on TwitterPlus on Google+


EmoticonEmoticon