Created on 31 Aug 2001; Reformat Oct 2002; Last Edit March 2005

Demonstration of oncontextmenu Event Handler

Works in: IE5+ Windows; Netscape 6.1/Win; Netscape 6.2/Linux; Safari 1.2/Mac; (Mozilla) Firefox 0.8 to 10.1/Mac+Win. Send me a note if you find it works in something else!

When right clicking here, the contextual menu* is disabled.

Here, on the other hand, it's enabled.

Contextual menu = what you get when you right click under Windows: Read more about it http://www.blooberry.com/indexdot/html/tagpages/attributes/oncontextmenu.htm and note that this event is not implemented in all browsers.

Source code:

<!--code originated by joe crawford www.artlung.com-->
<form action="../">
   <P>
      <span oncontextmenu="forms[0].elements[0].value++; return false">
         When right clicking here, the contextual menu* is disabled. 
      </span>

      <input type="text" value="0">
   </P>

   <P>
      <span oncontextmenu="forms[0].elements[1].value++">
         Here, on the other hand, it's enabled. 
      </span>
      <input type="text" value="0">
   </p>
</form>

Comments from Readers

Ian writes:

In Firefox by going to tools>options>web features>javascript and unselecting Allow scripts to Disable or replace context menus, then right click is allowed, however unlike Opera, it still dispatches right click to the script, and thus the count increases.

Don't you think the document should have a list of browsers it is known NOT to work in?

Well, I dunno. The intent of the page is just to show the simplest possible implementation. Keeping a table of every browser it doesn't work was not my intention. However, if someone wants to do that work I'll be happy to insert it above.

Regards, Joe