addLoadEvent Function


/ Published in: JavaScript
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.