Multiple onLoad 2 | JavaScriptSource

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

(7 comments)

thank you

Atthaporn Jan 21, 2014

thank you

Atthaporn Jan 21, 2014

There's a principle of programming that one always checks other programmer's parameters. In this case, it's appropriate to check the prior onload function for soundness. Here's what I use: var prioronloadPNjgw = window.onload; window.onload = onloadPNjgw; // my onload function onloadPNjgw() { // Attempted external call for other scripts // that need to handle the onload event: if ( prioronloadPNjgw != null) { try { prioronloadPNjgw() } catch(e){ alert("problem loading prior script") } }; // my onload code continues here

Jim Williams Jul 13, 2013

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