Html程序  |  56行  |  1.6 KB

<html>
<script type="text/javascript">

function context_event(event)
{
  if (window.event)
  {
    event = window.event;
  }
  var swallow = document.getElementById("swallow_context").checked;

  var str =
         "EVENT PROPERTIES<br>"                       +
         "cancelable      = "+event.cancelable+"<br>" +
         "ctrlKey         = "+event.ctrlKey+"<br>"    +
         "metaKey         = "+event.metaKey+"<br>"    +
         "shiftKey        = "+event.shiftKey+"<br>"   +
         "<br>"                                       +
         "TEST PROPERTIES<br>"                        +
         "prevent default = "+swallow+"<br>"          +
         "event time      = "+new Date()+"<br>"       +
         "";
  document.getElementById("event_info").innerHTML=str;

  if (swallow)
  {
    if ((typeof event.cancelBubble) != "undefined")
      event.cancelBubble=true;

    if ((typeof event.preventDefault) != "undefined")
      event.preventDefault();

    if ((typeof event.returnValue) != "undefined")
      event.returnValue = false;

    if ((typeof event.stopPropagation) != "undefined")
      event.stopPropagation();

    return false;
  }

  return true;
}

</script>

<body oncontextmenu="return context_event(event)">
<div>To activate context menu, right-click or ctrl-click anywhere on the page.</div>
<div>&nbsp;</div>
<div><input type="checkbox" value="1" name="swallow_context" id="swallow_context"> Prevent default context menu</div>
<div>&nbsp;</div>
<tt id="event_info" style='background-color:#eeeeee'>
 -- No event captured --
</tt>
</body>
</html>