Introduction: In previous articles i explained How to show message box and redirect to another page/website in visual studio using JavaScript. and JavaScript validations in asp.net website and Message box in asp.net website using JavaScript.
In this article i will explain how you can disable right click on your asp.net website with the help on JavaScript. Sometimes you don't want to allow anyone to copy the text or images from your website pages for the security of your content and images .So it is recommended to disable the right click on your website so that no one can copy the content and images from your website. Lets understand this using JavaScript.
Now check by right clicking on the web page.You will not be able to copy anything because nothing will happen on right clicking.
In this article i will explain how you can disable right click on your asp.net website with the help on JavaScript. Sometimes you don't want to allow anyone to copy the text or images from your website pages for the security of your content and images .So it is recommended to disable the right click on your website so that no one can copy the content and images from your website. Lets understand this using JavaScript.
- To do so, place following script in the head tag of your design file of asp.net
<head runat="server">
<script language=JavaScript>
var message = "";
if (event.button == 2) {
alert(message);
return false;
}
}
function clickNS4(e) {
if (document.layers || document.getElementById
&& !document.all) {
if (e.which == 2 || e.which == 3) {
alert(message);
return false;
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown = clickNS4;
}
else if (document.all
&& !document.getElementById) {
document.onmousedown = clickIE4;
}
document.oncontextmenu = new Function("return false")
</script>
</head>
Now check by right clicking on the web page.You will not be able to copy anything because nothing will happen on right clicking.
If you have any question about any post, Feel free to ask.You can simply drop a comment below post or contact via Contact Us form. Your feedback and suggestions will be highly appreciated. Also try to leave comments from your account not from the anonymous account so that i can respond to you easily..