Download one of the files below and either incorporate it into your code or serve it as a separate file.
|runOnLoad.js||335 bytes||Minified version|
|runOnLoad.src.js||1,543 bytes||Full version, with comments|
Tasks are added by passing them to the function:
1 2 3 4 5 6 7
Tasks can be added at any time; if a task is added after the content has loaded then it will be run immediately.
The function listens for two events, and runs the tasks as soon as one of the events fires.
In browsers that support the standard addEventListener function (browsers other than Internet Explorer 8 or lower) the function listens for the DOMContentLoaded and load events. The DOMContentLoaded event fires in browsers more recent than Chrome 0.2, Firefox 1.0, Internet Explorer 9, Safari 3.1, and Opera 9.0. The load event fires in all browsers, but only once all external files have loaded.
In browsers that only support the attachEvent function (Internet Explorer 8 or lower) the function listens for the readystatechange and load events. The readystatechange event fires in Internet Explorer 8. The load event fires in all versions, but only once all external files have loaded.