You are here: Reference > JavaScript > client-side > event handling > events > oncontextmenu

oncontextmenu event | contextmenu event

Browser support:
Occurs when the right mouse button is clicked on an element and the context menu is shown.
The oncontextmenu event is cancelable, if you cancel it, the context menu is not shown.
Although the oncontextmenu event is cancelable in Firefox, the user has the ability to forbid it (Tools - Options - Content - Advanced button for JavaScript - Disable or replace context menus).

How to register:

<ELEMENT oncontextmenu="handler">

In JavaScript:
object.oncontextmenu = handler;
object.addEventListener ("contextmenu", handler, useCapture);
object.attachEvent ("oncontextmenu", handler);
You can find the related objects in the Supported by objects section below.
The event object is accessible to all event handlers in all browsers. The properties of the event object contain additional information about the current event. To get further details about these properties and the possible event handler registration methods, please see the page for the event object.
For a complete list of events, see the page for Events in JavaScript.

Basic information:

Bubbles Yes
Cancelable Yes
Event object MouseEvent

Actions that invoke the oncontextmenu event:

  • Clicking on the right mouse button on an element.

The order of events related to the oncontextmenu event:

  1. onmousedown
  2. onmouseup
  3. oncontextmenu

Example HTML code 1:

This example illustrates the use of the oncontextmenu event:
Right-click on the following lines:
<br /><br />
<span>Context menu is enabled for this text.</span>
<br /><br />
<span oncontextmenu="return false">Context menu is disabled for this text.</span>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content