OverRide or Append to JavaScript onload event


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

Not my Code, credit is in the URL.


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. if (oldonload) {
  8. oldonload();
  9. }
  10. func();
  11. }
  12. }
  13. }
  14.  
  15. addLoadEvent(nameOfSomeFunctionToRunOnPageLoad);
  16. addLoadEvent(function() {
  17. /* more code to run on page load */
  18. });

URL: http://www.webreference.com/programming/javascript/onloads/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.