A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/html/html-oncontextmenu-event-attribute/ below:

HTML | oncontextmenu Event Attribute

HTML | oncontextmenu Event Attribute

Last Updated : 16 Aug, 2022

This attribute works when the user right-clicks on an element to open the context menu.
Supported Tags: 

Syntax: 
 

<element oncontextmenu="script">


Attribute Value: This attribute contains single value script. The script to be run when oncontextmenu attribute called. It is supported by all HTML elements.
Note: This attribute is new in HTML 5.
Example: 
 

html
<!DOCTYPE html>
<html>
    <head>
        <title>oncontextmenu Event Attribute</title>
        <style>
            div {
                background: Green;
                border: 1px solid black;
                padding: 10px;
                width:60%;
                color:white;
            }
            h1 {
                color:green;
            }
        </style>
    </head>
    <body>
        <center>
        <h1>GeeksforGeeks</h1>
        <h2>oncontextmenu Event Attribute</h2>
        <div oncontextmenu="myFunction()" contextmenu="mymenu">
            

<p>Right-click inside this box</p>


        </div>
        <script>
            function myFunction() {
                alert("You right-clicked inside the div!");
            }
        </script>
        </center>
    </body>
</html>

Output: 
 


Supported Browsers: The browser supported by oncontextmenu attribute are listed below: 
 



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4