oncontextmenu event | contextmenu event
10.5 | ||||
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:
In HTML:
In JavaScript:
<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:
- onmousedown
- onmouseup
- 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?
|
Supported by objects:
document
HTML elements:
a, abbr, acronym, address, applet, area, b, bdo, big, blink, blockquote, body, button, caption, center, cite, code, dd, del, dfn, dir, div, dl, dt, em, embed, fieldset, font, form, h1, h2, h3, h4, h5, h6, hr, html, i, img, input:button, input:checkbox, input:file, input:image, input:password, input:radio, input:range, input:reset, input:search, input:submit, input:text, ins, isindex, kbd, keygen, label, legend, li, listing, marquee, menu, nobr, noframes, object, ol, optgroup, option, p, plaintext, pre, q, rt, ruby, s, samp, select, small, span, strike, strong, sub, sup, table, tbody, td, textarea, tfoot, th, thead, tr, tt, u, ul, var, xmp
Related pages:
External links:
oncontextmenu (MSDN)
oncontextmenu (Mozilla Developer Center)
oncontextmenu (Safari Reference Library)
oncontextmenu (Mozilla Developer Center)
oncontextmenu (Safari Reference Library)
User Contributed Comments