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
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

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

  




 

 

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

The JavaScript FAQ
Prev Home Next


 
 
  Mirrored with kind permission of Alexei Kourbatov Design by Interspire