/ Published in: JavaScript
Ever wanted to add multiple functions to the onload event rather than one? This function lets you achieve exactly that.
Expand |
Embed | Plain Text
/* This function lets you add multiple functions to the Load event of the document. Example Usage : addLoadListener(firstFunction); addLoadListener(secondFunction); addLoadListener(twentyThirdFunction); */ function addLoadListener(fn) { if (typeof window.addEventListener != 'undefined') { window.addEventListener('load', fn, false); } else if (typeof document.addEventListener != 'undefined') { document.addEventListener('load', fn, false); } else if (typeof window.attachEvent != 'undefined') { window.attachEvent('onload', fn); } else { var oldfn = window.onload; if (typeof window.onload != 'function') { window.onload = fn; } else { window.onload = function() { oldfn(); fn(); }; } } }
You need to login to post a comment.
