On Jul 21, 2005, at 8:29 AM, Drake, Ted C. wrote:
I hope this is on-topic.
Javascript and DOM are web standards, and on topic. They just aren't
talked about much.
Many of us are already using the great Zebra Tables from
Alistapart.com
It requires an onload event for the body tag and to include a link
to the
javascript file.
Your solution is to add the onload handler within the script, instead
of within the body tag. Then you can include the script whenever you
need it.
If there are no other onload handlers, and never will be (you know
the future, right?), then you can assign it easily enough by adding
these lines to the end of the referenced script file:
window.onload = foo;
...where "foo" is the name of the function you want to call onload.
Be careful: you are adding a reference to the function, and you are
not *calling* the function here. That's why there are no parentheses
after foo. Here's how I remember that: parens mean "do this", so when
the window "does" its onload, it calls "onload()". If you assigned
"foo()" to "onload", then the window would call "onload()()" and
that's not right, is it? The parens get added when the thing happens;
for now, don't put them in.
Now, a cleaner way to add the onload is to preserve any existing
onload handler, instead of overwriting it. That way you can add a
fancy shmancy javascripted menu system later. You could write your
own function, or use this:
function addToOnLoad(fn) {
var Prev = window.onload || function () {};
window.onload = function () { Prev(); fn(); }
}
addToOnLoad(foo);
This function is drastically simplified from the truly compatible
version (but works Win IE5-6, Gecko, Safari, not Mac IE, although I
*thought* it did). To use it, *all* onload handlers need to be
assigned this way; the first one assigned in the body tag throws out
all the others. So:
addToOnLoad(foo);
addToOnLoad(bar);
addToOnLoad(baz);
The DOM provides a better means to do this, but IE isn't on board
with it yet, so there are a hundred scripts out there for this basic
idea.
--
Ben Curtis : webwright
bivia : a personal web studio
http://www.bivia.com
v: (818) 507-6613
******************************************************
The discussion list for http://webstandardsgroup.org/
See http://webstandardsgroup.org/mail/guidelines.cfm
for some hints on posting to the list & getting help
******************************************************