[thelist] Wanted: the definitive fool-proof mouseover JavaScript

.jeff jeff at members.evolt.org
Tue Jun 26 22:02:23 CDT 2001


paola,

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: From: Paola Kathuria
:
: I'm looking for short, maintaintable, and
: bug-free mouseover JS.
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

http://members.evolt.org/jeff/code/preload_n_rollover/

preloading included, no extra charge.

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: I currently use something that tests for
: certain browsers and versions, hence it
: not working with Konqueror:
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

never do useragent detection.  object detection is so much cleaner and
applicable.

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: I'd prefer a solution that doesn't refer to
: browser makes/versions at all but which also
: won't produce any JS error messages on any
: browser (no matter how old).
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

sorry to say that's a utopian non-existence.  you can eliminate the errors
for all browsers and increase the necessary maintenance (and consequently
the file size) or make it work for 99.9% of the cases and never have to fuss
with it (and keep it much smaller).

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: I have had a rummage around on Google and have
: found two common approaches: testing for browser
: make/version and the if(document.images) version
: (also seen with no JS version).  The latter one
: is elegant but, sadly, produces a JS error in
: IE 3.  True, there can't be many people using
: IE 3 but I'd still prefer a script that didn't
: produce any error messages at all.
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

you think they're not used to seeing those errors by now?  practically every
site on the net has some sort of image rollover.  most do not even do object
or browser detection.

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: The first SCRIPT is there for pre 1.1 JS browsers
: which will see the function call in the HREFs
: (otherwise you get an error message).  The second
: script will then overwrite the function definitions
: for JS 1.1+ browsers.
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

have you tested whether or not the older, troublesome browsers understand
the different language values?  my guess is that ie3 will ignore the js1.1
language specification and try to read the contents anyway.  i was quite
surprised to see that nn2.02/win didn't do that, but wouldn't be surprised
if there were some that did (nn3/win, for example, ignores js1.2
declarations and reads the contents anyway).

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: I like this as the code is cleaner without the
: conditionals.  However, is it legal to define
: the same function in consecutive JS scripts?
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

sure.

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: (And are the braces needed in the empty function
: calls?)
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

yes.  try it without -- you'll get errors.

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: If not, the alternative is to have the first script
: be JavaScript1.1 and have it set a variable.  The
: second script (which doesn't need a JS version)
: then just has to test whether tha variable has been
: set before the image and function definitions.
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

seems like alot of extra work for a browser that you may never have at your
site.  you're sending extra kb down the pipe for *every* browser so you can
catch the problem for likely less than 0.1% of your browser users.  it's a
noble thought to try to make it as bug free as possible for those ie3 users,
but not all noble thoughts are the most appropriate thoughts.

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: Any ideas?
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

yeah, object detection.

if(document.images)

good luck,

.jeff

http://evolt.org/
jeff at members.evolt.org
http://members.evolt.org/jeff/






More information about the thelist mailing list