On 01/21/2011 07:57 AM, Rene wrote:
> I think that we better could do <body onload='init()'>
>
> This has the benefit that if someone else want to do something on
> load he could add it in the init function.

It is not necessary to codify one inline init function--JavaScript 
programs can share event handlers without having any knowledge of each 
other. (Admittedly it's a little verbose, but it works.) Below is the 
basic JavaScript pattern for adding something to an event handler 
without clobbering any existing event handlers and without polluting the 
global namespace. (It doesn't guarantee that no later script will 
clobber this one, but nothing can guarantee that.)

(function(){
   var myInit = function(){
     // do stuff
   };
   if(window.onload) {
     var oldOnload = window.onload;
     window.onload = function(){
       oldOnload.apply(this,arguments);
       myInit.apply(this,arguments);
     }
   } else {
     window.onload = myInit;
   }
})()


-- 
Joshua Paine
LetterBlock: Web applications built with joy
http://letterblock.com/
301-576-1920
_______________________________________________
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users

Reply via email to