Javascript DOM onshow Event

Introduction

Execute a JavaScript when a <menu> element is shown as a context menu:

This example demonstrates how to assign an "onshow" event to a menu element.

The onshow event is currently only supported in Firefox.

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
div {/*from www .j  a  v  a 2s.co  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="image7.png"></menuitem>
  <menu label="Share on...">
    <menuitem label="Twitter" icon="image5.png" onclick="window.open('//twitter.com/intent/tweet?text=' + window.location.href);"></menuitem>
    <menuitem label="Facebook" icon="image6.png" onclick="window.open('//facebook.com/sharer/sharer.php?u=' + window.location.href);"></menuitem>
  </menu>
  <menuitem label="Email This Page" onclick="window.location='mailto:?body='+window.location.href;"></menuitem>
</menu>
</div>
<p id="demo"></p>
<script>
function myFunction() {
  document.getElementById("demo").innerHTML = "The context menu is about to be shown";
}
</script>

</body>
</html>

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

Bubbles: No
Cancelable: No
Event type: Event
Supported HTML tags: <menu>



PreviousNext

Related