HTML oncontextmenu event Attribute

❮ HTML Event Attributes


<a href="" oncontextmenu="myFunction()">Right click me!</a>

function myFunction(){
  alert("You right-clicked!");


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


Attribute Values

Value Description
script Specifies the script to be run on oncontextmenu

Technical Details

Supported HTML elements:

All HTML elements
❮ HTML Event Attributes