Posted By

Butscharoni on 11/09/07


Tagged


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

basicmagic
heinz1959
korzhik
jamesming


Execute after page load


 / Published in: JavaScript
 

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

Simon Willsons page load fix.

  1. function addLoadEvent(func) {
  2. var oldonload = window.onload;
  3. if (typeof window.onload != 'function') {
  4. window.onload = func;
  5. } else {
  6. window.onload = function() {
  7. if (oldonload) {
  8. oldonload();
  9. }
  10. func();
  11. }
  12. }
  13. }
  14.  
  15. addLoadEvent(nameOfSomeFunctionToRunOnPageLoad);
  16. addLoadEvent(function() {
  17. /* more code to run on page load */
  18. });

Report this snippet  

You need to login to post a comment.