October 10, 2001 - Detecting An Event within A Page
October 10, 2001 Detecting An Event within A Page Tips: October 2001
Yehuda Shiran, Ph.D.
|
attachEvent()
method. The attachEvent()
syntax is as follows:
object.attachEvent(event, eventHandler);
If there is an additional event handler defined for the object the event fired on, it will be run before the function eventHandler()
is called. If you attach several event handlers to the same page, they will be called in a random order, immediately after the object's event handler is run, if at all defined.
Let's take an example. In the page's init()
function you can ask that the function mouseDownHandler()
be called when the onmousedown
event fires:
document.attachEvent("onmousedown", mouseDownHandler);
And you can determine the object it fired on by going:
objectClicked = event.srcElement.id;