Javascript DOM onshow Event via HTML Tag onshow attribute

Introduction

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  va 2s. co m
  background: yellow;
  border: 1px solid #cccccc;
  padding: 10px;
}
</style>
</head>
<body>

<p id="demo"></p>
<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>
<script>
function myFunction() {
  document.getElementById("demo").innerHTML = "The context menu is about to be shown";
}
</script>

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



PreviousNext

Related