Link to Test Page
CSS max-device-width and the screen.width property are often unreliable
My experiments with most of the browsers running on the GTab indicate a problem with both these attributes at the most important time, when the page is first loaded. Frequently, a value that is widely off will be reported on first load and you will only get the correct value when you refresh the page. Obviously, this is not acceptable because you can't force a page reload as soon as the user accesses your page. You can see this with the Test Page link above (see below for code). On first load on the GTab, the dimensions will often be off, but they will correct themselves on reload.
The user agent string is often spoofed and unreliable on tablet devices
Tablet users often want to access the full versions of websites, not the mobile versions designed for mobile phones. This isn't possible on the stock browser on the GTab but other browsers like Dolphin HD make this possible by allowing the user to change the User Agent setting. When you switch this to "Desktop" Dolphin pretends it's Chrome on Windows. Other browsers pretend to be Mobile Safari on a Mac, even in default mode. You can no longer depend on the user agent string to identify the platform or the browser on mobile devices, and this problem will be much more common on mobile devices than on desktop machines.
At the moment I seem to be getting very reliable results without checking device width or the user agent string with this strategy:
- First eliminate old and less capable mobile browsers, which CAN be done with the user agent string (Symbian, Series 60, Windows CE, Blackberry)
- Check for iOS devices (iPhone and iPad) -- this can be done very reliably with a unique identifier that Apple kindly provides.
- Check for mobile and touch OS capabilities. This can also be done very reliably by polling for the actual attributes and events. If they are there you can be sure that you're in a mobile OS and a touch OS.
As far as I can see, this gives you a reliable way of identifying the two really important mobile tablet operating systems: Apple iOS and Android. iPad and iPhone are identified directly. Android is also identified directly if its name is in the user agent string. However, if you're not in another browser, not in an iOS device but are in a mobile OS and a touch OS then you can be 99% sure that you're on Android. Once you've got that, then you can go about setting up your CSS and your other parameters for your page.
Here is the Test Page link again and I include the basic quick-and-dirty source code of the page below. The page should be yellow on mobile browsers and white otherwise, but this is done on the basis of the max-device-width CSS attribute and it will sometimes fail on the GTab on first load.
I'd be grateful to hear if anyone finds the code incorrectly reporting an Android device.
Why you need this information:
You need to make sure that you're really on a touch OS tablet and not a netbook, which may have similar screen dimensions. Also, the capabilities of Android browsers are different in important ways from those of Mobile Safari on iOS. For example, you can scroll frames and scrollable elements with two fingers on Mobile Safari, but Android browsers can't scroll these elements at all. Also, Android browser's multi-touch support is different in some ways.
An interesting additional observation:
On all the GTab browsers I've tested so far the document.documentElement dimensions and the screen.width/screen.height dimensions are identical. This is NOT the case on any desktop browsers, so this can probably be used as an additional test.