onload eventHandler

recently handgestrickt netzwerk had the problem, that two scripts had to be added to one of our customers websites and both scripts needed an onload eventHandler. the problem is, that only the last eventHandler will be excecuted. so we needed a solution for this. the best one is to collect all function calls in one function and then execute this function onload.

Simon Willison wrote a handy Javascript function for this called addLoadEvent:

function addLoadEvent(func) {   var oldonload = window.onload;   if (typeof window.onload != 'function') {     window.onload = func;   } else {     window.onload = function() {       oldonload();       func();     }   } } //examples addLoadEvent(nameOfSomeFunctionToRunOnPageLoad); addLoadEvent(nameOfAnotherFunctionToRunOnPageLoad);

source: http://simon.incutio.com/archive/2004/05/26/addLoadEvent

Friday, 28. April 2006 • trackback url

Add Comment

( to reply to a comment, click the reply link next to the comment )

Comment Title:
Your Name:
Email Address:
Make Public?
Website:
Make Public?

Comment:


Allowed XHTML tags : a, b, i, strong, code, acrynom, blockquote, abbr. Linebreaks will be converted automatically.


Captcha:

captcha image

please type the content of the above image into the following form-field: