Return to Snippet

Revision: 19295
at October 20, 2009 18:04 by codegoat


Initial Code
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() {
  /* more code to run on page load */ 
});

Initial URL
http://simonwillison.net/2004/May/26/addLoadEvent/

Initial Description

                                

Initial Title
Add Onload Event

Initial Tags
event

Initial Language
JavaScript