by http://webgeektutorials.blogspot.com

Monday, May 21, 2012

jQuery: Disable context menu on right click

Using jQuery you can disable context menu when you right click on any HTML page. To do so add a very small   script in <HEAD> section of HTML page after linking it to jQuery.

Here is the script : 

<script type="text/javascript">
 $(function(){
 $("form").form();
 $(this).bind("contextmenu", function(e) {
e.preventDefault();
 });
});
</script> 


After putting this script to the header section of your page, <head> section looks like this


</head>
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>


<script type="text/javascript">
 $(function(){
 $("form").form();
 $(this).bind("contextmenu", function(e) {
e.preventDefault();
 });
});
</script>
</head>

No comments:

Post a Comment