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.
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
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. |
|||
|
|||
0 comments :
Note: Only a member of this blog may post a comment.