General
Need to load several functions after the page loads? Use this snippet to call several functions using the onLoad event handler. Easy to use.
Notes
- Created by: Simon Willison
- Web Site: http://simon.incutio.com/
- Posted: June 29, 2007
See the notes at: “Executing JavaScript on Page Load“
Source Code
Paste this source code into the designated areas.
External file
Paste this code into an external JavaScript file named: multipleOnload.js and load it last. Or, if you use one file for several scripts, you can add it to the bottom of page.
/* This script and many more are available free online at
The JavaScript Source!! http://javascriptsource.com
Created by: Simon Willison | http://simon.incutio.com/ */
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != ‘function’) {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}
addLoadEvent(nameOfSomeFunctionToRunOnPageLoad);
addLoadEvent(function() {
functionHere();
});
Head
Paste this code into the HEAD
section of your HTML document.
<script type=”text/javascript” src=”multipleOnload.js”></script>