[thelist] addLoadEvent overwritten by onload attribute of body tag

James Denholm-Price j.denholmprice at gmail.com
Thu Aug 3 04:24:04 CDT 2006


Hi :-)

On 25/07/06, Ben Glassman <bglassman at gmail.com> wrote:
> ...I used the addLoadEvent function to add functions to window.onload.
> Their developer is now running into issues because they keep trying to
> add rollovers and other javascript using dreamweaver...
> ... Is there a solution to this ...
> I think I'm basically asking there is another addLoadEvent function, I
> think I'm using Simon Willison's, that will someone not get overridden
> by the body onload tag?

By SW's do you mean [1]?

If-so, you might be able to get around the problem in every modern
browser by using DOM-style methods of adding event handlers:

SW's [1] keeps <body onload...> happy & is good provided everyone uses
the function.

If instead you the DOM event listeners, e.g. PPK [2] or Scott Andrew
[3], and your Dw developers use <body onload="..."> then both your
scripts and their stuff should still execute in modern browsers that
support attachEvent (IE5/6) or addEventListener (DOM2, e.g. Mozilla.)

Unfortunately yours will still get overridden in browsers that don't
support the DOM-style but that would be an unusual/old browser...

Btw, the execution order seems to vary, e.g. try my demo page [4] in
IE and Firefox ;-)

HTH,
           James

[1] http://simon.incutio.com/archive/2004/05/26/addLoadEvent
[2] http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html
[3] http://www.scottandrew.com/weblog/articles/cbs-events
[4] http://staffnet.king.ac.uk/~ku13043/test/test_load_event.htm



More information about the thelist mailing list