"Fotios" <> wrote in message
news:3f6e4683$0$214$...
>>User agent detecting is unnecessary in almost all cases but of the
>>methods that have been attempted the use of the browser's
>>navigator.userAgent string is easily the most useless as very few
>>current browsers report consistent or accurate information in this
>>string. Often in order to avoid this type of clumsy and misguided
>>detection categorising them as "unknown" or "declined" when their
>>JavaScript and DOM support is entirely up to the requirements
>>of the majority of scripts and their authors can see no reason for
>>them to be excluded just because some script author only knows
>>enough to recognise 7 browsers by name.
>
>I rarely read something as inacurate as what you have just written.
So you haven't bothered to read the comp.lang.javascript FAQ before
posting then:-
<URL:
http://jibbering.com/faq/#FAQ4_26 >
- as it says essentially the same thing. (Still, I don't expect you
would consider that a document that is subject the scrutiny and review
of all of the regular poster to this group as having anything accurate
to say on the subject of browser scripting.)
>What about the fact that most script that goes around does not run
>properly in more than one or two browsers?
"most script that goes around" is written (or more often cut-n-pasted)
by people who do not really understand what they are doing and should
not be taken as an example of best (and in many cases not even
acceptable) practice.
>A detector is about "what is" not about "what ought to be".
So test "what is" not "what ought to be" which is what you are testing
by assuming that the navigator.userAgent string ought to be a
discriminating indicator of the type and version of a web browser. It is
not and has not been for quite some time now.
As it is your code will identify Konqueror 3 as IE, Netscape, Opera,
Konqueror and unknown depending on which of the userAgent string I
choose form the list of 20 odd provided in the drop-down in the
preferences. While the same script will be absolutely convinced that my
Palm OS web browser is IE 6, but a script that treats it as IE 6 will
fail horribly. To qualify as a "detector" a script should be expected to
produce discriminating results. The navigator.userAgent string just
cannot provide that.
But, as I said, it is almost never necessary to know the browser type or
version. Feature detection is the preferred strategy. A script author
should know what features a browser must support in order for a script
to work. Testing for the existence of those features prior to execution
allows a script to execute in any browser that supports them and if they
are not available it can cleanly and harmlessly exit. A strategy that is
only interested in "what is" available on the browser in question, but
without any interest in which browser that actually is. Also a strategy
that can work successfully in a completely unknown browser, exploiting
any browser up to its ability to support the script.
Richard.