W3C home > Mailing lists > Public > www-dom@w3.org > October to December 2001

Re: What is the meaning of the DOM ECMAScript binding?

From: Jim Ley <jim@jibbering.com>
Date: Fri, 9 Nov 2001 14:50:47 -0000
Message-ID: <00bb01c1692d$ecd96700$ca969dc3@emedia.co.uk>
To: <www-dom@w3.org>
"Neil Laurance":
> --- Jim Ley <jim@jibbering.com> wrote:
> Jim. Could you elucidate what you mean by 'object detection'. I am not
> with this term.

Object detection, if you want to choose between using two different
objects, you literally see which object is available and use that

if (window.document) doc=window.document
 else if (window.neil) doc=window.neil

The only risk of this technique is if window.document exists but isn't
what you think it is, this can be checked with a "typeof object" - but in
general that's rarely needed as it's very unlikely and currently unknown
that getElementById is going to be anything but the standard function. so
is generally not checked for.

This can of course be followed through to any object

if (document.getElementById) el=document.getElementById('moomin')
if (moomin && moomin.style) moomin.style.backgroundColor='red'

etc. this way any browser which supports the relevant objects it will
work on, and any others it won't error.  You need to check every object


has more on this (watch out for other mozilla pages...)

Received on Friday, 9 November 2001 09:51:50 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 20 October 2015 10:46:09 UTC