[thelist] [javascript] Window.onload > YUI vs. Prototype

Matt Warden mwarden at gmail.com
Mon Apr 7 00:12:59 CDT 2008

On Sun, Apr 6, 2008 at 11:47 PM, Paul Bennett <Paul.Bennett at wcc.govt.nz> wrote:
>  Well, someone has been clever and done some update work, placing the lightbox includes *above* the common js includes on about 100 pages. The consequence is that lightbox no longer works on these pages, as it seems when window.onload is called the 2nd time it wipes out previous event handlers.(?)

Yes, this happens. Consider:

var foo = 'bar';

then later:

foo = 'junk';

The variable foo will obviously equal "junk" after this, not "bar".

Same thing:

window.onload = function() {alert('bar');};

then later:

window.onload = function() {alert('junk');};

Your subject line mentions YUI but the body does not, so I'm guessing
a bit as to where that comes into play. However, YUI does have a
mechanism to assist in adding something to window.onload without
wiping out anything already on that event.


See also:

Matt Warden
Cincinnati, OH, USA

This email proudly and graciously contributes to entropy.

More information about the thelist mailing list