I have a script that can be loaded at any stage of the life cycle of a web page. When the script loads, it should run the initialize () method.
I want this function to fire in the "onload" event, but I cannot be sure that the page is not loaded yet, i.e. that "onload" was no longer running.
Ideally, my script would look like this:
var _initialize = function() { ...}; if(window.LOADED) _initialize(); else if (window.addEventListener) window.addEventListener('load', _initialize, false); else if (window.attachEvent) window.attachEvent('onload', _initialize);
Is there such a window .LOADED or document.LOADED or something like that?
Thanks in advance, Shane
Shane source share