addLoadEvent function


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

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


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

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.