Posted By

alberomo on 07/25/11


Tagged

function onload manual Simon Willison


Versions (?)

addLoadEvent function


 / Published in: JavaScript
 

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

Description: Execute different functions when the page loads in a better way than default onload JS event. Include it in the end of the JS document. Arguments: Name of the function that you want to execute when the page loads. Author: Simon Willison

  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. }

Report this snippet  

You need to login to post a comment.