HTML and CSS Reference
In-Depth Information
Client-Side userAgent Detection
There are times when you must detect the userAgent and parse it accordingly. Typically,
you can determine the browser by inspecting JavaScript's window.navigator object or
by using the userAgent request header on the server side. This approach may work for
most browsers, but it's not dependable, as noted in a recent bug report for the MobileESP
Issue Summary: When using the Firefox browser on an Android mobile phone, the Mo‐
bileESP code library erroneously reports the device as an Android tablet. An Android
tablet is correctly identified as an Android tablet. This issue only affects mobile phones
and similar small-screen Android devices like MP3 players (such as the Samsung Galaxy
Root Cause: Mozilla uses the exact same userAgent string for both phones and tablets.
The string has the word 'Android' in both. According to Google guidelines, Mozilla should
include the word 'mobile' in the userAgent string for mobile phones. Unfortunately,
Mozilla is not compliant with Google's guidelines. The omission of the word 'mobile' is
the reason why phones are erroneously identified as tablets.
So if userAgent detection isn't always dependable, when is it a good choice to use?
• When you know, ahead of time, which platforms you are supporting and their UA
strings report correctly. For example, if you care about only the environment (not
its features) your application is running in, such as iOS, you could deliver a custom
UI for that environment only.
• When you use it in combination with feature-detection JavaScript that calls only
the minimum functions needed to check the device. For example, you may not care
about the discrepancy in the reported string, because it's unneeded information.
You might only care that it reports TV, and everything else is irrelevant. This also
allows for “light” feature detection via JavaScript.
• When you don't want all JavaScript-based feature tests to be downloaded to every
browser and executed when optimizations based on userAgent -sniffing are avail‐
Yahoo! has its own reasons for using userAgent detection:
At Yahoo we have a database full of around 10,000 mobile devices. Because user
Agent strings vary even on one device (because of locale, vendor, versioning, etc.), this
has resulted in well over a half a million user agents. It's become pretty crazy to maintain,
but is necessary because there's really no alternative for all these feature phones, which
can't even run JavaScript.
Search WWH ::

Custom Search