[Greasemonkey] Running before a pre-defined event handler

Aaron Boodman zboogs at gmail.com
Thu Dec 22 18:45:17 EST 2005


Handler processing order is undefined for event handlers which have
the same target and the same capture flag. However -- assuming I'm not
on crack -- the event order otherwise is defined as:

* capture handlers from document root down to element
* handlers on element (foo.onclick and <foo onclick="...")
* non-capture handlers from element up to document root

That was sorta the whole point of the three-phase event system.

- a

On 12/22/05, Johan Sundström <oyasumi at gmail.com> wrote:
> > 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/
> _______________________________________________
> Greasemonkey mailing list
> Greasemonkey at mozdev.org
> http://mozdev.org/mailman/listinfo/greasemonkey
>


More information about the Greasemonkey mailing list