Return to Snippet

Revision: 2422
at February 13, 2007 05:55 by 1man


Initial Code
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

//usage
addLoadEvent(firstFunction);
addLoadEvent(secondFunction);

Initial URL

                                

Initial Description
Use this function to queue functions you wish to load on window onload. Very useful when code becomes complex.

Initial Title
addLoadEvent Function

Initial Tags
js, DOM

Initial Language
JavaScript