Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

oncontextmenu event

oncontextmenu event

Event Object Reference Event Object

Example

Execute JavaScript when the user right-clicks the mouse on the element:

element when the mouse is right-clicked to execute JavaScript:

Try it »


Definition and usage

The oncontextmenu event is triggered when the user right-clicks the mouse in an element and opens the context menu.

**Note:** All browsers support the oncontextmenu event, contextmenu but the element is only supported by the Firefox browser.


Browser support

Events
oncontextmenu Yes Yes Yes Yes Yes

Syntax

In HTML:

<

element

oncontextmenu="

myScript

">

Try it

In JavaScript:

object

.oncontextmenu=function(){

myScript

};

Try it

In JavaScript, use the addEventListener() method:

object

.addEventListener("contextmenu",

myScript

);

Try it

Note: Internet Explorer 8 and earlier IE browser versions do not support addEventListener() .


Technical Details

Does it support bubbling: Yes
Is it cancelable: Yes
Event type: MouseEvent
Supported HTML tags: All HTML elements

Event Object Reference Event Object