I choosed this demo because it clearly show that interaction with the DOM can start before images are loaded.
|
|
NOTES:
The "document.write", and the "onerror" handlers you see on the images TAGS in the HTML has nothing to do with the javascript solution, they have been inserted in this example trying to break this example with inline writes or scripts or reloading fresh images each time.
Enable "Javascript writing to Status Bar" in your browser to see the order of events in the status bar.
If there are images in the page the difference is very big, if not it will sill fire before the onload event.
It is important also to note that in any case our event does not have to fire before inline scripts, in the same way as it happen by using the "DOMContentLoaded" or "onreadystetchange" events. I am not contrary to using these events, I use them myself in my complete solution, and if you are interested there is also a "DOMFrameContentLoaded" which works in FF > 1.5 and Opera > 9, which I use to control the iframes in the same way.
What I really wanted is collect all the available methods to discover various moment in the page loading process to study and fully understand how this exactly works and feel myself as a controller of this process and not ajust an observer. With this in mind, I have found that the following may be the moments in which users are interested during page load.
Between all these moment the one that I have found resumes most of the capabilities found in other methods is "Before Images".
This is the smallest and most portable code I have come across. But I will soon release a more complete solution, that will accept an optional parameter passed to the setup function, this parameter will be exactly one of the moments described above. So it will be possible to fire "Load Events" in the exact moment the users needs, I have seen everybody needs their special setup capability and I would like to give a complete answer to all.
It isn't an easy task as you may have come to know, but it is very instructive, and I have a very good use for it and events in general.