Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




The JavaScript FAQ
Prev Home Next

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") 
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. Copyright © 1999-2006, Alexei Kourbatov

The JavaScript FAQ
Prev Home Next

  Mirrored with kind permission of Alexei Kourbatov Design by Interspire