Also, while it's convenient to insert javascript event handlers into
HTML
markup when demonstrating an example, in practice it's probably best
to
leave the script out of the markup and apply it from a separate
script file
at window.onload.
One beef I have with this code, and most code of this nature, is that
it uses this to trigger it:

        window.onload = externalLinks;

This is fine, if it's the only code you are assigning to onload, but it
overwrites any previous onloads and is overwritten by subsequent
onloads.

http://www.bivia.com/sandbox/crossfade_slideshow/ test_bv_addListener.html


Wow, your method looks elaborate.

A bit. But you put it in a central utilities-script file, and then all you need to do is call it so you never need to see the elaboration. Instead of the DOM:


        el.addEventListener('event', func, bool);

...you call a function that does the same, but cross-browser:

        bv_addListener(el, 'event', func);


Another method I've imagined but never implemented is for each added function to add itself to an array of functions.

This is essentially how I used to do it. Each js file that housed a certain behavior would have this at the end:



if (!window.ToLoad) window.ToLoad = new Array(); window.ToLoad[window.ToLoad.length] = someFuncName; window.onload = function() { for (var xx = window.ToLoad.length -1; xx >= 0; xx--) { window.ToLoad[xx](); } }


It's efficient. Your imagination is should try it. Notice that it uses FILO ordering of the handlers (that's First In, Last Out, or reverse order from being added).


The advantage to my other code is that it adds any event handler to any event on any object. So, in this case, the same code could be used to cue the init script, and the init script could use it to add the onclick handlers.

--

        Ben Curtis
        WebSciences International
        http://www.websciences.org/
        v: (310) 478-6648
        f: (310) 235-2067




****************************************************** The discussion list for http://webstandardsgroup.org/

See http://webstandardsgroup.org/mail/guidelines.cfm
for some hints on posting to the list & getting help
******************************************************



Reply via email to