Javascript window.loader object (v 4.1)

What does it do?top ↑ 

I was never a fan of doing anything to the HTML onLoad as this can be problematic. The window loader object is slightly less bad in as much as it will fire when the DOM page structure has loaded
download form sourceforge.net

Test data

You should see red and green indicators showing if the DOM as loaded (just the HTML) and the window (the HTML and all the assets, images etc...)

DOM loaded! :)

Window loaded! :)

How to use?top ↑ 

Put the loader.js in to the head of your HTML page before any other js files

<script src="js/loader.js" type="text/javascript"></script>		
	

Create and pass in any functions you want to run. Most of the time you'll be using the oncontentready method, the onload method is commonly used for preloading images and other assets you want to have ready if the user requests them. You wouldn't use oncontentready to preload images as the page is still busy loading assets

example usage on this page

// Does the useagent have required js support?
window.jsActive = (window.attachEvent || window.addEventListener) ;

// useragent is ok and window.loader exists 
if (window.jsActive && window.loader){ 
	window.loader.oncontentready(showDomLoad);
	window.loader.onload(showWindowLoad);
	
	// add more functions 
	//loader.oncontentready(myotherfunction);
	//loader.onload(myotherfunctionLoad);
}

Download this javascirpt object

What else do I need to know?top ↑ 

text

TODOtop ↑ 

  • Elegant fall back
  • More browser testing

Supported browsers

  • IE 6 +
  • Firefox 2 +
  • Opera 9 +
  • Safari 2.0.4 (via a very nasty setInerval)
  • Not sure about others yet

Trouble shooting

Nothing fires at all
your browser might not be supported
The DOM load is not working and everything is being run on window.onload (IE)
there might be some other javascript that is preventing the document body from being ready when the ondocumentready fires

Bugs and issuestop ↑ 

tbc

DOM loaded! :)

Window loaded! :)