[Greasemonkey] addEventListener example doesn't work?

Lenny Domnitser ldrhcp at gmail.com
Mon Sep 19 17:05:14 EDT 2005


On 9/19/05, Ryan Forsythe <ryan at flamingweasel.com> wrote:
> if (!window.addEventListener('load', function() { scan(); }, true)) {
>    scan();
> }

addEventListener does not return any value, so it will always evaluate
to false. The above example is the same as writing:

    window.addEventListener('load', function() { scan(); }, true);
    scan();

GM 0.5.3 has some bugs, but with everything working properly, this
code can cause the function to be called twice. Without
addEventListener working, the code can be abbreviated to:

    scan();

Which means that addEventListener is unnecessary in this example.
Since GM executes when the DOM loads, in most cases there is no need
to add a load event (note that this executes after everything loads,
including images, etc, whereas GM runs right after the DOM is
created).


More information about the Greasemonkey mailing list