Context menu Attribute in HTML5
In this article I am going to describe about the implementation and use of contextmenu attribute in HTML5
The contextmenu attribute specifies a context menu for an element. The context menu appears when a user right-clicks on the element. Contentmenu Attribute is new in HTML5.
The value of the contextmenu attribute is the id of the <menu> element to open.
Menu items may have
onclick attributes to represent design and actions.
contextmenu is a lot simpler than you may think. All you need is to add the
contextmenu attribute like so:
Add anything you want here
As you can see you can add it just like you would add any
Next we create the menu:
<menu type="context" id="my-right-click-menu">
Here we will add the new 'right-click' menu items
Currently it is Not supported by any of the major browsers.
|| The id of the <menu> element to be open
Example of Context menu attribute in HTML5
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<meta charset="utf-8" />
<title>Context menu Attribute in HTML5</title>
<p contextmenu="menu">This paragraph has a context menu called "menu". The context menu should appear when a user right-clicks on this paragraph.</p>
<command label="Write Tutorial" onclick="doSomething()">
<command label="Edit Tutorial" onclick="doSomethingElse()">
<p>Contextmenu is not currentlly supported in any browser</p>