Trapping Event Handlers

[Total: 0    Average: 0/5]

This file shows how to obtain Event information for any type of event.

Body Code:

<form name="form">
<input name="button" type=button value="Button"><BR>
<input name="reset type=reset><BR>
<input name="submit" type=submit><BR>
<input name="radio" type=radio> Radio Button<BR>
<input name="checkbox" type=checkbox> Checkbox<BR>
Select 1: <Select name="menu">
<option>Option 1</Option>
<option>Option 2</option>
<option>Option 3</option>
</Select>
Select any: <select multiple name="List">
<option>Option 1</Option>
<option>Option 2</option>
<option>Option 3</option>
</Select>
Text: <input name="text" type=text><BR>
Password: <input name="password" type=password><BR>
File: <input name="fileupload" type=file><BR>
Textarea: <textarea name="textarea" rows=2 cols=20>
</textarea><BR>
</form>
link: <a href="javascript:void(0)">This is a link</a><BR>
image: <img src="/images/blue_ball0.gif">
<script type=text/javascript>
var _p1 = "width=300,height=600,scrollbars,resizable,menubar";
var ewin=window.open("","EventTester",_p1)
var isNS=navigator.appName.indexOf("Netscape")  != -1
var isIE=navigator.appName.indexOf("Microsoft") != -1
handler.docopen=false
function handler(e) {
  var d=ewin.document
  if (!handler.docopen) {
    d.open("text/plain")
d.writeln("TEXT")
handler.docopen=true
  }
  if (isNS) {
    d.writeln("Type: "+ e.type)
if (e.target) d.writeln("Target: "+
  Object.prototype.toString.apply(e.target))
if (e.target.name) d.writeln("Target name: "+e.target.name)
if (e.x||e.y) d.writeln("X: "+e.x+" Y: "+e.y)
if (e.which) d.writeln("Which: "+e.which)
if (e.modifiers) d.writeln("Modifiers: "+e.modifiers)
  }
  if (isIE) {
    //e = window.event
    //e = event
return
if (e.type)                          d.wirteln("Type: "+e.type)
if (e.srcElement&&e.srcElement.name) d.writeln("srcElement name: "+e.srcElement.name)
if (e.clientX||e.clientY)            d.writeln("X: "+e.clientX+" Y: "+e.clientY)
if (e.button)                        d.writeln("Button: "+e.button)
if (e.keyCode)                       d.writeln("KeyCode: "+e.keyCode)
if (e.altKey)                        d.writeln("altkey")
if (e.ctrlKey)                       d.writeln("ctrlKey")
if (e.shiftKey)                      d.writeln("shiftKey")
e.cancelBubble=true
  }
  d.writeln()
  if (handler.timeoutid) ewin.clearTimeout(handler.timeoutid)
  handler.timeoutid=
    setTimeout("ewin.document.close();handler.docopen=false","1000")
}
function addhandlers(o) {
  o.onblur=handler
  o.onabort=handler
  o.onchange=handler
  o.onclick=handler
  o.ondblclick=handler
  o.onerror=handler
  o.onfocus=handler
  o.onkeydown=handler
  o.onkeypress=handler
  o.onkeyup=handler
  o.onload=handler
  o.onmouseodown=handler
  o.onmouseout=handler
  o.onmouseover=handler
  o.onmouseup=handler
  o.onmove=handler
  o.onreset=handler
  o.resize=handler
  o.onselect=handler
  o.onsubmit=handler
  o.onunload=handler
}
addhandlers(window)
addhandlers(document)
for (var d=0;d<document.links.length;d++)
  addhandlers(document.links[d])
for (var d=0;d<document.images.length;d++)
  addhandlers(document.images[d])
for (var d=0;d<document.forms.length;d++) {
  addhandlers(document.forms[d])
  for (var e=0;e<document.forms[d].elements.length;e++)
    addhandlers(document.forms[d].elements[e])
}
</script>

Times Viewed: 3

Leave a Reply

Your email address will not be published. Required fields are marked *