Disable Mouse Right Click using JavaScript

Today we teach you how to disable mouse right click using JavaScript in website or asp.net webpage.
The script to disable right-click event is very quick.
 
Disable Mouse Right Click using JavaScript

 

With this script in your Master tab, you will deactivate the right-click event on the entire website. In previous posts, we have discussed Get Google Map API Directions with JavaScript, Get Computer Hardware Information and ASP.NET Static Websites, Submit multiple points to Google Map, Send eMail with an Appendix, Check for Grid View with JavaScript, HTML to PDF with iTextSharp library. Now we are going to deactivate the right mouse click with JavaScript.

 ADD SCRIPT

The script above has to be copied into the main section of the ASP.NET (ASPX) page and can be put in the ContentPlaceHolder. The script deactivates the following three events to disable the right click of your navigation.

 OnMouseDown

 The script first checks whether the document has layers, and if yes then the OnMouseDown event is captured and inside its event handler the event is cancelled by using return false.

 OnMouseUp

 And if the document does not have layers then inside the OnMouseUp event handler, first the Mouse Button that was clicked is determined and if the Button is Middle or Right then the event is cancelled using return false.

 OnContextMenu

The OnContextMenu event is cancelled using the OnContextMenu event handler.



2:  Disable text selection in a page


This javascript disables the ability to select text with mouse. You can try it on this page (works on IE and FF).

 
<SCRIPT type="text/javascript">
if (typeof document.onselectstart!="undefined") {
  document.onselectstart=new Function ("return false");
}
else{
  document.onmousedown=new Function ("return false");
  document.onmouseup=new Function ("return true");
}
</SCRIPT>
 

But it's not a good "defence," because with simple javascript url you can return to normal conduct:

Post a Comment

[blogger]

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget