Velocity Reviews

Velocity Reviews (
-   Javascript (
-   -   FAQ Topic - How do I detect Opera/Safari/IE? (2012-02-19) (

FAQ server 02-19-2012 12:00 AM

FAQ Topic - How do I detect Opera/Safari/IE? (2012-02-19)
FAQ Topic - How do I detect Opera/Safari/IE?

The short answer: _Don't do that_.

The `navigator` host object contains properties which
may identify the browser and version. These properties are historically
inaccurate. Some browsers allow the user to set `navigator.userAgent` to any value. For
example, Firefox, (type `about:config` and search `useragent`
or Safari, `Develop > User Agent > Other...`, IE, via Registry.

Other browsers, such as Opera, provide a list of user agents
for the user to select from. There are also at least 25 other
javascript capable browsers, with multiple versions, each
with their own string.

Browser detection is unreliable, at best. It usually causes
forward-compatibility and maintenance problems. It is unrelated to the
problem or incompatiblity it is trying to solve and obscures the
problems it is used for, where it is used.

Object detection is checking that the object in question exists.

goes one step further to actually test the object,
method, or property, to see if behaves in the desired manner.

Feature Test Example:

* Returns the element/object the user targeted.
* If neither DOM nor IE event model is supported, returns undefined.
* @throws TypeError if the event is not an object.
function getEventTarget(e) {
e = e || window.event;
// First check for the existence of standard "target" property.
return || e.srcElement;


The complete comp.lang.javascript FAQ is at


The sendings of these daily posts are proficiently hosted

All times are GMT. The time now is 08:30 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.