Browser determination

Many javascript snippets I've seen test to see what kind of browser they are running in using the following methods:

the boolean value of (document.getElementById) is used to indicate whether or not the browser is DOM compatible

the boolean value of (document.all) is used to determine if the browser is IE4

the boolean value of (document.layers) is used to determined if the browser is Netscape 4.

I'd like a brief explanation of why these properties indicate the corresponding browsers.  Thanks.
chsalviaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RoonaanCommented:
Because document.layers is not available in IE4 or other browsers and document.all is not available in Netscape.

document.getElementById is currently the most used function to retrieve specific elements in a html tree. In older browsers this function does not exists and therefor needs to be testen on, when you have people with older browser versions in your target public.

-r-

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Michel PlungjanIT ExpertCommented:
However document.all is supposedly available in Opera.
JeffHowdenCommented:
You shouldn't be testing for browser.  Instead, you should be testing for object/method support prior to using something that may or may not be supported by the user's browser.
rkattanCommented:
to detect you could check for
window.opera
which is not supported by any other browser

and to correctly check for IE with document.all you need to do
if (document.all && !window.opera)

like this you exclude opera with document.all
JeffHowdenCommented:
For so many reasons, browser detection is the *wrong* way to go.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.