Javascript: Detect when a window is fully loaded
问题 I have a script which may be loaded at any stage of the life cycle of a web page. When the script is loaded it must run an initialize() method. I want this function to be run on the "onload" event, but I cannot be certain that the page has not already loaded, i.e. that the "onload" has not been fired already. Ideally my script would look like this: var _initialize = function() { ...}; if(window.LOADED) _initialize(); else if (window.addEventListener) window.addEventListener('load',