Browser determination

Posted on 2006-04-17
Medium Priority
Last Modified: 2011-10-03
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.
Question by:chsalvia
LVL 49

Accepted Solution

Roonaan earned 168 total points
ID: 16475549
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.

LVL 75

Expert Comment

by:Michel Plungjan
ID: 16475641
However document.all is supposedly available in Opera.

Assisted Solution

JeffHowden earned 164 total points
ID: 16475682
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.

Assisted Solution

rkattan earned 168 total points
ID: 16475997
to detect you could check for
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

Expert Comment

ID: 16481483
For so many reasons, browser detection is the *wrong* way to go.

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question