Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Disable Mouse Right Click on Page using JavaScript and jQuery in Asp.net

Mar 17, 2015
Introduction

Here I will explain how to disable right click in asp.net (aspx) webpage using
JavaScript and jQuery. To disable right click on page using JavaScript and jQuery we need to disable oncontextmenu event, onmousedown and onmouseup events.

Description:
  
In previous articles I explained jQuery change image on mouse over, jQuery social sharing plugin examples,
jQuery Hover dropdown menu, jQuery bouncing menu example, jQuery zoom image on mouse over using zoom plugin, jQuery split string into array by comma and many articles relating to AngularJS, jQuery, JavaScript and asp.net. Now I will explain how to disable right click in asp.net (aspx) webpage using JavaScript and jQuery.

To disable right click on web page we need to write the code like as shown below


<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1">
<title>Sample to Disable Right Click of Page</title>
<script language="JavaScript" type="text/javascript">
if (document.all) {
document.onmousedown = click;
}
else {
document.onclick = click;
}
//Message to display whenever right click on website
var message = "Sorry, Right Click have been disabled.";
function click(e) {
if (document.all) {
if (e.button == 2 || e.button == 3) {
alert(message);
return false;
}
}
else {
if (e.button == 2 || e.button == 3) {
e.preventDefault();
e.stopPropagation();
alert(message);
return false;
}
}
}
document.oncontextmenu = function () {
return false;
};
</script>
</head>
<body>
<form id="form1">
<div>
</div>
</form>
</body>
</html>

Live Demo

For live demo try to right click on this page and check whether is it allowing or not

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

0 comments :

Give your Valuable Comments

Other Related Posts

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.