[thelist] Pontification on object and method detection (was: Wanted: thedefinitive fool-proof mouseover JavaScript)

Paola Kathuria paola at limitless.co.uk
Fri Jun 29 01:05:19 CDT 2001


Joe Crawford wrote:
> Still, /intuitively/ if you're going to use an object, you should test for
> the object.

Yup.  Remember, though, that the alternative script only came
up because I thought *cough* that testing for document.images
still resulted in JS Image errors for IE 3 (and so I suspected
on other older browsers too).

> But the problem I have, is that it is so very /tied/ to a peculiarity of how
> the <script> tag works.

I confess that I have very limited experience with JavaScript;
I just use it for mouseovers and leave anything else to my
colleagues.

However, even with my limited experience, I wouldn't say that
the pair of scripts is exploiting a *peculiarity* of the
script tag.  My understanding is that the language version
in the script tag is *meant* to be used to tell browsers which
scripts they should attempt running.

My first script will always run in all JS-enabled browsers -
the second will (okay, should) only run in browsers that
implement JS 1.1 or above.   "if (document.images)" tests
for a specific object -  this new pair of scripts tests for
a minimum JS language version.   Different test, same result
for plain ol' mouseover code.

The O'Reilly book acknowledges that Netscape doesn't perform
to standard when it comes across a JavaScript1.2 declaration
(which is, I presume, the version problems that Jeff was
referring to), but there's nothing in that chapter about
browsers not honouring version 1.1 declarations.

> I don't have confidence that new browsers will
> implement their scripting engines in the same way.

It'll be interesting to see if they do or not.

(And I'd like to see a ref to formal docs that say it's
okay to define the same function in consecutive scripts.)

> I initially coded http://www.artlung.com/archive/2/home.html back in 1997,
> and the mouseovers still work. They worked in Netscape 3. They didn't make
> IE3 break.

Erm, reading this is when I double-checked my initial premise:
that testing for document.images doesn't prevent JS Image errors
in IE 3.  My premise was wrong.  Ooops.

When looking for alternatives to my 1997 mouseover script (which
does explicit browser make/version testing), I went to look at
HP's mouseover code at http://www.hp.com/   I saw that they used
document.images tests.  When I viewed the page in IE 3, I got
a JS Image error, which I assumed meant that testing for
document.images didn't work.

Me and Frank seem to have come up with an alternative
approach unnecessarily, it seems.  *blush*

> And I'll add that these browsers which I have handy execute your script
> properly:
>     Netscape 6.1pr1/Mac
>     MSIE5/Mac
>     Opera 5.0tp3.298/Mac

Thanks.

> Again, it's interesting that this technique is working, but I instinctively
> don't trust it. It just seems logical that one would test for an object
> before using it - rather than making blank functions for older browsers,
> then making the real function for newer browsers.

Crikey, I'd be the first to admit that they're a scary pair of
scripts, which is why I mailed here about it.  There is a
logic to them - although they are, perhaps, a tad obscure.

Ho hum.


Paola




More information about the thelist mailing list