[Greasemonkey] Running before a pre-defined event handler
Johan Sundström
oyasumi at gmail.com
Fri Dec 23 01:37:29 EST 2005
> Another way to do this would be to use the capture flag of event listeners. So:
>
> // true for 3rd arg makes this a capturing event listener
> node.addEventListener(event, handler, true);
>
> See: http://www.w3.org/TR/DOM-Level-2-Events/events.html for more information.
Really? I'd want you to be right, but the way I read that, the order
of event handler
invocation is undefined, irrespective of the event capture flag (which is also
consistent with me not getting that to work when I tried that route). Quoting
http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-flow-basic
"Although all EventListeners on the EventTarget are guaranteed to be triggered
by any event which is received by that EventTarget, no specification is made as
to the order in which they will receive the event with regards to the other
EventListeners on the EventTarget."
followed up in the next section on event capture by
"If the capturing EventListener wishes to prevent further processing
of the event
from occurring it may call the stopProgagation method of the Event interface.
This will prevent further dispatch of the event, although additional
EventListeners
registered at the same hierarchy level will still receive the event."
I believe a similarly awkward kludge might be made to work by registering a
capturing event handler on the hierarchy level above the node I want to monitor,
filtering out events not destined for the particular node, but that
somehow feels
like it would be even more work.
--
/ Johan Sundström, http://ecmanaut.blogspot.com/
More information about the Greasemonkey
mailing list