
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
HTML oncontextmenu Event Attribute
The HTML oncontextmenu event attribute is triggered when the user right clicks on an HTML element to open the context menu in an HTML document.
Syntax
Following is the syntax −
<tagname oncontextmenu=”script”></tagname>
Example
Let us see an example of HTML oncontextmenu event Attribute −
<!DOCTYPE html> <html> <head> <style> body { color: #000; height: 100vh; background-color: #FBAB7E; background-image: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%); text-align: center; padding: 20px; } .box { background: #db133a; width: 140px; height: 140px; margin: 1rem auto; color: #fff; } </style> </head> <body> <h1>HTML oncontextmenu Event Attribute Demo</h1> <p oncontextmenu="get()" class="box"></p> <p>Now try to right click on above red box to open context menu.</p> <script> function get() { document.body.style.background = "#084C61"; document.body.style.color = '#fff'; } </script> </body> </html>
Output
Now try to right click on the red box to observe how oncontextmenu event attribute work.
- Related Articles
- HTML onblur Event Attribute
- HTML onclick Event Attribute
- HTML onchange Event Attribute
- HTML oncopy Event Attribute
- HTML oncut Event Attribute
- HTML ondrag Event Attribute
- HTML onfocus Event Attribute
- HTML oninput Event Attribute
- HTML oninvalid Event Attribute
- HTML onpaste Event Attribute
- HTML onresize Event Attribute
- HTML onreset Event Attribute
- HTML onsubmit Event Attribute
- HTML onscroll Event Attribute
- HTML onsearch Event Attribute

Advertisements