Advertisement
Gerst20051

Generic Onload

Nov 20th, 2013
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //GO1.1 :: Generic onload by brothercake - http://www.brothercake.com/
  2.  
  3. //onload function
  4. function generic()
  5. {
  6.     alert('Generic onload function');
  7. };
  8.  
  9.  
  10. //setup onload function
  11. if(typeof window.addEventListener != 'undefined')
  12. {
  13.     //.. gecko, safari, konqueror and standard
  14.     window.addEventListener('load', generic, false);
  15. }
  16. else if(typeof document.addEventListener != 'undefined')
  17. {
  18.     //.. opera
  19.     document.addEventListener('load', generic, false);
  20. }
  21. else if(typeof window.attachEvent != 'undefined')
  22. {
  23.     //.. win/ie
  24.     window.attachEvent('onload', generic);
  25. }
  26.  
  27. //** remove this condition to degrade older browsers
  28. else
  29. {
  30.     //.. mac/ie5 and anything else that gets this far
  31.    
  32.     //if there's an existing onload function
  33.     if(typeof window.onload == 'function')
  34.     {
  35.         //store it
  36.         var existing = onload;
  37.        
  38.         //add new onload handler
  39.         window.onload = function()
  40.         {
  41.             //call existing onload function
  42.             existing();
  43.            
  44.             //call generic onload function
  45.             generic();
  46.         };
  47.     }
  48.     else
  49.     {
  50.         //setup onload function
  51.         window.onload = generic;
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement