We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

1man on 02/13/07


Tagged

js DOM addLoadEvent


Versions (?)


Who likes this?

3 people have marked this snippet as a favorite

dmarten
vali29
1man


addLoadEvent Function


Published in: JavaScript 


Use this function to queue functions you wish to load on window onload. Very useful when code becomes complex.

  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. oldonload();
  8. func();
  9. }
  10. }
  11. }
  12.  
  13. //usage
  14. addLoadEvent(firstFunction);
  15. addLoadEvent(secondFunction);

Report this snippet 

You need to login to post a comment.