addEventListener("show", myFunction); - Javascript DOM Event

Javascript examples for DOM Event:addEventListener

Description

The onshow event occurs when a <menu> element is shown as a context menu.

Summary

Bubbles No
Cancelable No
Supported HTML tags: <menu>

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
div {//from   w w w  . java 2s  .  c  o  m
    background: yellow;
    border: 1px solid #cccccc;
    padding: 10px;
}
</style>
</head>
<body>

<div contextmenu="mymenu">
<p>Right-click inside this box to see the context menu!

<menu type="context" id="mymenu" onshow="myFunction()">
  <menuitem label="Refresh" onclick="window.location.reload();" icon=""></menuitem>
  <menu label="Sub menu">
    <menuitem label="A" icon="" onclick="console.log('a')"></menuitem>
    <menuitem label="B" icon="" onclick="console.log('b')"></menuitem>
  </menu>
  <menuitem label="C" onclick="console.log('c')"></menuitem>
</menu>
</div>

<script>
document.getElementById("mymenu").addEventListener("show", myFunction);

function myFunction() {
    console.log("The context menu is about to be shown");
}
</script>

</body>
</html>

Related Tutorials