HTML oncontextmenu event Attribute

❮ HTML Event Attributes

Example

<a href="https://www.google.com" oncontextmenu="myFunction()">Right click me!</a>

<script>
function myFunction(){
  alert("You right-clicked!");
}
</script>

Meaning

The oncontextmenu attribute is called when a context menu is invoked generally by right-click. Can be fired by direct targeting of the element or the event bubbling up.


Standard Syntax

<element oncontextmenu="script">

Browser Support




Status







Attribute Values

Value Description
script Specifies the script to be run on oncontextmenu



Technical Details

Supported HTML elements:

All HTML elements
❮ HTML Event Attributes