Update: 2014 March 19 - domReady version II has been created that provides a streamlined domReady function.
Update: 2008 Feb 14 - Added support for Vista 64 per Goran Miskovic's comment.
For those of you that don't know what the DOMContentLoaded event can do for you, here's a brief description.
The DOMContentLoaded event allows you to add behavior or change the HTML of a page after the HTML has loaded and before the onload event which happens after the complete page, including images has loaded. This allows you to add menu, tree behavior, AJAX functionality or anything else without having to wait for all items on a page to load. You may have experienced the need for a DOMContentLoaded event on a page that includes drop down menus or a tabbed interface which doesn't work until all images have loaded. Using the DOMContentLoaded event allows you to add the behavior before images and objects have loaded.
When I originally added the DOMContentLoaded event handler to Dean Edwards' addEvent function, I didn't provide a way to handle calls to it after the DOMContentLoaded event handler ran. If a developer called
addEvent(window, "DOMContentLoaded", myFunction) after the DOMConentLoaded event ran, the passed function would never run. This version fixes the problem so that even if you call addEvent for the DOMContentLoaded event and the DOMContentLoaded event handler has already run, it will run your function.
The previous addDOMLoadEvent function would simply add the passed function to an array of functions which would be handled by the DOMContentLoadedInit function on the DOMConentLoaded event.
Continue Reading "DOMContentLoaded for Browsers, Part IV..."