oncontextmenuEvent

Event 对象参考手册Event Object

Examples

Execute JavaScript when the user right-clicks on a <div> element:

<div oncontextmenu="myFunction()" contextmenu="mymenu">

Try it Yourself »


Definition and Usage

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

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


Browser Support

Event
oncontextmenu Yes Yes Yes Yes Yes


Syntax

In HTML:

<element oncontextmenu="myScript">Try it Yourself

In JavaScript:

object.oncontextmenu=function(){myScript};Try it Yourself

In JavaScript, using the addEventListener() method:

object.addEventListener("contextmenu", myScript);Try it Yourself

Note:Internet Explorer 8 and earlier IE browser versions do not support itaddEventListener() 。


Technical Details

Does it support bubbling: Yes
Can it be cancelled: Yes
Event type: MouseEvent
Supported HTML tags: All HTML elements

Event 对象参考手册Event Object

Other Extensions