How do I disable right click on my asp.net web page or html page:

How to protect your web page by right click on page:




 I just want to protect my source code? Using this code will prevent the vast majority of users from right-clicking over a page and choosing "View source", or right-clicking over an image and saving it.

How do I disable right click on my web page:


Some times  the developer  might be the requirement to disable the pop up menu on click of right button.Programmers or developer may need to disable right click to prevent user from saving the images on the page or viewing the source of the page.

Though disabling right click is not complete solution to save the data, but it will make task difficult, or may be impossible for the rookies.

<script language="javascript">
document.onmousedown=disableclick;
status="Right Click Disabled";
Function disableclick(event)
{
  if(event.button==2)
   {
     alert(status);
     return false;   
   }
}
</script>
and
<body oncontextmenu="return false">
...
</body>
DON'T DO IT.  Because it achieves nothing other than annoying users. Also many browsers have a security option to disallow disabling of the right click (context) menu anyway.Not sure why you'd want to. If it's out of some misplaced belief that you can protect your source code.

Disable right click on web page and images:


Use the script below so when someone right clicks to save an image off your page, a message will come up letting people know that your information is copyrighted.

This script may not work in all browsers, and is not foolproof. If someone really wants something from your page they can find ways around it, but at least it's a warning to people who want to take your graphics. But it certainly is a great start.
Copy and paste the following code, and make sure it comes right after your <HEAD> tag:
<!--

var rclickmsg="Sorry, no right-clicking allowed in this  Page  ";

///////////////////////////////////
function clickIE4(){
if (event.button==2){
alert(rclickmsg);
return false;
}
}

function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
alert(rclickmsg);
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("alert(rclickmsg);return false")


// -->


Comments