[Javascript] Modern usage

David Dorward david at dorward.me.uk
Wed Apr 19 09:59:13 CDT 2006


On Wed, Apr 19, 2006 at 07:47:38AM -0700, Bill Moseley wrote:
> I'm seeing usage like 
>     if (document.images) {
> which from googling seems like that's testing for IE3's lack of
> support. 

Testing for one browser feature in order to guess what browser is
being used is a bad idea. Testing for document.images to see if
document.images is supported is a good idea.

> Do I need to worry about IE3 users today?

Not explicitly. Follow the principles of graceful degradation and
feature testing and things should "just work" on IE3.

> I also see
>     document.all
> instead of getElementByID.  What percent of browsers don't support
> that DOM method?

Only IE4.x supports document.all but not document.getElementById
AFAIK. This is a tiny proportion of the WWW. You might want to
consider it as a fallback.

I think you might also be able to so something like:

if (!document.getElementById && document.all) {
  document.getElementById = function (id) { 
    var el;
    var code = "el = document.all." + id;
    eval(code);
     return el;
  }
}

... but I've never tried it, nor care enough about IE4 to do so ... or
used eval in JavaScript for that matter.
 
> The page also is using ypSlideoutMenu from 2001.  Anyone familiar
> with this?  Would you consider it acceptable javascript?

As a rule of thumb, slide out menus are usually a bad idea with
usability and accessibility issues.

-- 
David Dorward                                      http://dorward.me.uk




More information about the Javascript mailing list