Jyoti Vinay Pandey Jyoti Vinay Pandey - 29 days ago 11
Javascript Question

How do I disable right click on my web page?

Can I disable right click on my web page without using Javascript? I ask this because most browsers allow user to disable Javascript.

If not, how do I use JavaScript to disable right click?

Answer

You can do so with Javascript and/or an HTML attribute (which is really a Javascript event handler anyway) as described here:

<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>

That being said: DON'T DO IT.

Why? 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 or images that way, think again: you can't.