Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   FAQ Topic - How do I detect Opera/Safari/IE? (2012-02-19) (http://www.velocityreviews.com/forums/t944644-faq-topic-how-do-i-detect-opera-safari-ie-2012-02-19-a.html)

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.

http://dev.opera.com/articles/view/u...ity-detection/

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.target || e.srcElement;
}

<URL: http://jibbering.com/faq/notes/detect-browser/>
<URL: http://dev.opera.com/articles/view/using-capability-detection/>
<URL: http://developer.apple.com/internet/webcontent/objectdetection.html>
<URL: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.43>


The complete comp.lang.javascript FAQ is at
http://jibbering.com/faq/

--

The sendings of these daily posts are proficiently hosted
by http://www.pair.com.



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.