Disable mouse right click using jQuery

Disable mouse right click using jQuery


In this article we will learn how to disable the mouse right click using jQuery which provides security to our HTML source code as well as its provides the security being copy or paste directly in form control.


[ul class=”list list-arrow_blue_3″]

[li] To use jQuery in an ASP.Net form you need to add the reference for the jQuery library that is nothing but a JavaScript file.[/li]

[li] You can download the latest  jQuery library from http://jquery.com/download/  [/li]


I hope ,you have downloaded above jQuery library for referencing a page because whenever we use any jQuery code then it must to give the jQuery library file reference into the page.

Let us Create the web application in asp.net to demonstrate the requirement by creating the web application as

  1. “Start” – “All Programs” – “Microsoft Visual Studio 2010”
  2. “File” – “New Website” – “C# – Empty website” (to avoid adding a master page)
  3. Give the web site a name, such as Validation or whatever you wish and specify the location
  4. Then right-click on the solution in the Solution Explorer then select “Add New Item” – “Default.aspx page”.

I hope,you have created page now,let us create the Jquery function to disable the mouse write click as:

  $(this).bind("contextmenu", function(e) {

Now add the jQuery library file reference at head section of the page and whole code is a follows :


Now run the application,and click on mouse right button,it will shows following message as:



It’s not better to give the alert message after right click because we are disabling right click because of mouse for  security purpose and by showing alert message we exposing our own  security by telling hacker or spammer i have disabled right click ,so always avoid right click alert message.

advantages using JQuery to disabled right click

  1. JQuery supports on every browser where as JavaScript failed for Sony Ericsson browser .
  2. many time when we give the alert message when we disabled the right click of mouse then after three attempt click right click will be enabled so its better to use Jquery.


I hope this small trick is useful for all readers ,if you have any suggestion regarding this article then please contact me.

Leave a Reply

Your email address will not be published. Required fields are marked *