[Greasemonkey] Running before a pre-defined event handler

Aaron Boodman zboogs at gmail.com
Thu Dec 22 08:19:33 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.

- a

On 12/21/05, Johan Sundström <oyasumi at gmail.com> wrote:
> I figured as it just took me well over an hour to diagnose and come up
> with a work-around for this issue, others in the same situation might
> be glad if I shared it on the list.
>
> I faced a problem where I wanted to add an onclick handler that would
> run prior to an already defined onclick handler in a page, as my handler
> was changing the lots of page state intended for the original handler to
> see. node.addEventListener( event, handler, false ); would install my
> own callback _after_ the already existing handler, which wouldn't do
> much good here.
>
> The kludge I came up with was adjusting the present node to wait for a
> decisecond before executing, so my greasemonkey injected hook would
> have ample time to do its business before it would run the original code:
>
> var code = node.getAttribute( 'onclick' );
> if( code )
>   node.setAttribute( 'onclick', 'setTimeout("' +code+ '", 100)' );
>
> Really ugly, but it does work. I'd love to hear of better solutions for
> this.
>
> --
> / 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