Right Button: Disabling
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 (beginning with Netscape Navigator 4.x and Internet Explorer 4.x)
you can disable the right-button menu by displaying an alert message on right-click.
To do so, insert the following
code in your page's <HEAD>
section:
<script language="JavaScript">
<!--
function mouseDown(e) {
if (parseInt(navigator.appVersion)>3) {
var clickType=1;
if (navigator.appName=="Netscape") clickType=e.which;
else clickType=event.button;
if (clickType!=1) {
alert ('Right mouse button is disabled.')
return false;
}
}
return true;
}
if (parseInt(navigator.appVersion)>3) {
document.onmousedown = mouseDown;
if (navigator.appName=="Netscape")
document.captureEvents(Event.MOUSEDOWN);
}
//-->
</script>
Note: 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.
JavaScripter.net.
Copyright
© 1999-2006, Alexei Kourbatov