revision:
This attribute specifies through the user right-clicks on an element to open the context menu.It supports all HTML elements.
<element oncontextmenu="script></element>
script: the script to be run on oncontextmenu.
<div style="margin-left:5vw;" id="menu" oncontextmenu="clickRight()" contextmenu="mymenu">
<p class="spec">Right-click inside this box</p>
</div>
<script>
function clickRight() {
alert("You right-clicked inside the div!");
}
</script>
Now right click on above red box to open context menu.
<div style="margin-left:3vw;color:white;" oncontextmenu="get()" id="box">Hi there !!</div>
<p class="spec">Now try to right click on above red box to open context menu.</p>
<script>
function get() {
document.getElementById("box").style.background = "#084C61";
document.getElementById("box").style.color = "darkblue";
alert("you right-clicked the box");
}
</script>