html tutorial - oncontextmenu Attribute in HTML - html5 - html code - html form

Oncontextmenu attribute in html

Learn html - html tutorial - Oncontextmenu attribute in html - html examples - html programs

  • The oncontextmenu attribute specifies through the user right-clicks on an element to open the context menu.
  • The oncontextmenu attribute is section of the Event Attributes.

Syntax for oncontextmenu attribute in HTML:

<element oncontextmenu = “script”>

Differences between HTML 4.01 and HTML5 for oncontextmenu attribute:

HTML 4.01

  • HTML4 does not support oncontextmenu attribute.


  • HTML5 support oncontextmenu attribute.

Applies To:

Element Attribute
All HTML Elements oncontextmenu

Attribute Values:

Value Description
script The script can run on oncontextmenu.

Sample Coding for oncontextmenu Attribute in HTML:

Tryit<!DOCTYPE html>
        <title>Wikitechy oncontextmenu attribute</title>
        <div style="background:cyan; padding:20px;"  oncontextmenu="onContextMenu()" contextmenu="wikiContext">         
        <p>Right click the box to View Wikitechy Context Menu </p>
        <menu type="context" id="wikiContext">
        <menuitem label="Wikitechy"   onclick="'');"   icon="icon.png">             
        <menu label="Online">
        <menu type="context" id="wikiContext">
        <menuitem label="Tutorials" icon="icon.png" onclick="
          function onContextMenu() 
             alert("You right-clicked inside the div!");


Code Explanation for oncontextmenu Attribute in HTML:

oncontextmenu Attribute Code Explanation

  1. oncontextmenu attribute is used to call the onContextMenu() function when the user Right-click the <div> element content.
  2. JavaScript function onContextMenu() is used to display an alert message.

Output for oncontextmenu Attribute in HTML:

oncontextmenuAttribute Tag Output

  1. The div content was displayed, when the page has been loaded.
oncontextmenu Attribute Tag Output

  1. When user right click over div element, the alert box has been displayed.
  2. After clicking the OK button in alert box, the context menu has been displayed.

Browser Support for oncontextmenu Attribute in HTML:

No No Yes No No

Related Searches to oncontextmenu Attribute in html

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add to your ad blocking whitelist or disable your adblocking software.