Javascript DOM onshow Event via HTML Tag onshow function

Introduction

In JavaScript:

object.onshow = function(){
       myScript};

This example uses the HTML DOM 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  ww  w . ja va2  s  .  c  o  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">
  <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").onshow = function() {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