Right Mouse Button:
Disabling the Context Menu

JavaScript FAQ | Keyboard & Mouse Events FAQ  

Question: Can I disable the Windows context menu that normally shows up when the user clicks the right mouse button?

Answer: In most modern browsers, you can disable the context menu by using the oncontextmenu event handler in the body tag of your page:

<body oncontextmenu="return false;">
Try right-clicking anywhere on this page - the context menu won't show up!

In older browsers that do not support the oncontextmenu event handler (e.g. Netscape Navigator 4.x and Internet Explorer 4.x) you can disable the right-button menu by an onmousedown event handler displaying an alert message on right-click. In very old browsers (Netscape Navigator 3.x, Internet Explorer 3.x or earlier) the context menu would still show up. Also, the context menu will be displayed if the user has disabled JavaScript.

Copyright © 1999-2011, JavaScripter.net.