Javascript DOM onshow Event via addEventListener() method

Introduction

In JavaScript, using the addEventListener() method:

object.addEventListener("show",
       myScript);

This example uses the addEventListener() method to attach a "show" event to a menu element.

The show event is currently only supported in Firefox.

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
div {/*from   w w w .ja  v a  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!

<p id="demo"></p>
<menu type="context" id="mymenu">
  <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>
document.getElementById("mymenu").addEventListener("show", myFunction);

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