Multiple onLoad 2

Simon Willison Jun 29, 2007

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

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.


Head

Paste this code into the HEAD section of your HTML document.


Leave a Response

(4 comments)

Well, that is what it does here. As each onload function listed in the script is encountered, it is executed. Then, it moves on to the next one.

Lee Nov 18, 2008

How do keep 3 onload functions from executing at once? I want to execute them sequentially...when one completes execution I want to begin execution of the next one?.

Warren Taylor Nov 15, 2008

Sure, you would want to enter the name of the function to load, e.g.,[br /][br /]Use this one:[br /]addLoadEvent(yourFunction);[br /][br /]or this one:[br /][br /]addLoadEvent(function() {[br /]yourFunctionHere();[br /]});

Lee Jul 26, 2007

addLoadEvent(nameOfSomeFunctionToRunOnPageLoad);[br /]addLoadEvent(function() {[br /] functionHere();[br /]});[br /]That bit at the end seems to imply to my inexperienced mind that I should enter something here.[br /][br /]Not quite sure what to do. Can you help?

rodger myles Jul 6, 2007