• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
JavaScriptSource

JavaScriptSource

Search 5,000+ Free JavaScript Snippets

  • Home
  • Browse Snippets
    • Addon
    • Ajax
    • Buttons
    • Cookies
    • CSS
    • Featured
    • Forms
    • Games
    • Generators
    • Image Effects
    • Math Related
    • Miscellaneous
    • Multimedia
    • Navigation
    • Page Details
    • Passwords
    • Text Effects
    • Time & Date
    • User Details
Home / Addon / Multiple onLoad 2

Multiple onLoad 2

Multiple onLoad 2

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>

Addon

Related Snippets:

  • getElementsByAttribute
  • insertAfter()
  • Remove HTML Tags
  • getXML

Primary Sidebar

Popular Posts

Story Generator

IP Grabber – get a users IP address with JavaScript

Simple Calendar

Remove Ads

Astrological Calculator

Copyright © 2025 JavaScriptSource.com

  • About
  • Privacy Policy
  • FAQ
  • Jobs For Developers