HTML oncontextmenu Event Attribute

Description

The event attribute oncontextmenu allows you to set the script to trigger when the context menu on the element is called.

Syntax

<element oncontextmenu="script">

Values

  • scriptThe name of the script to use when the event has been triggered.

Example

<!DOCTYPE html> 
  <html> 
    <head>
      <title>oncontextmenu event</title> 
    </head> 
    <body> 
    <div contextmenu="testmenu" oncontextmenu="testFunction()">Click on me with the right mouse button.
    <menu type="context" id="testmenu"> 
      <menuitem label="like"> </menuitem> 
      <menuitem label="dislike"> </menuitem> 
    </menu> 
    </div> 
<script> 
function testFunction () { 
  alert("You are invoking the context menu! Will only work in Firefox"); 
} 
</script> 
  </body> 
</html>

Supported Tags

All HTML tags.

Browser Support

Desktop
Explorer Edge Chrome Firefox Opera Safari
XYesYesYesXX
Tablets / Mobile
Android Chrome Firefox Opera Safari Samsung
XXXXXX