Forum Moderators: open

Message Too Old, No Replies

When does onload get triggered?

After all assets on the page have rendered, or HTML only?

         

Fotiman

3:18 pm on Apr 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Supppose I have a page with a lot of large <objects> or images. Say these take 30 seconds to completely finish loading in a browser (that is, all images viewable, flash objects viewable, etc.). Does the body onload event get triggered after all of that, or does it get triggered sometime before when the "guts" of the HTML have been rendered?

The HTML spec says:

"The onload event occurs when the user agent finishes loading a window"

But I don't know how to interpret that.

Thanks.

pinterface

12:59 am on Apr 19, 2006 (gmt 0)

10+ Year Member



onload doesn't fire until all content is either loaded or has failed to load. In the quite likely event you want to fire events before that, mozilla provides a DOMContentLoaded event, and IE has something similar.

Dean Edwards does a pretty good job explaining the approach [dean.edwards.name] (and an alternate way [dean.edwards.name] for IE).

Fotiman

2:31 pm on Apr 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks pinterface. That was exactly the information I was looking for. It confirms that the onload event is triggered after ALL content has loaded (including images and other binary content).

Thanks.