I want to use Modernizr to detect whether a user is view a site on a desktop, tablet or mobile device.
My initial first thoughts are obviously to check screen sizes that should be enough for mobile devices and also for larger desktops. For tablet devices where the screen size could also equal that of a small desktop screen (1024 x 768) I would test for touch events as well.
At this time I would like to focus on mobile/tablet devices that, as jQuery mobile puts it are, A-grade. I am not looking to tap in to any specific mobile device features simply detect desktop, tablet or mobile and serve up a tailored UI for each by appending CSS classes depending on the results of the test.
Do you think this is enough to achieve what I want or do you think I should be testing for other capabilities? Many thanks in advance.
Modernizr can check for touch events
For testing whether the device is a tablet or phone or desktop, I would probably lean more toward using User Agents. Take a look at the scripts on DetectMobileBrowsers.com
Modernizr simply tests for whether or not a browser supports certain features. As far as I know, it doesn't appear to test
browser_type == mobile
and stuff along those lines...Keep in mind that a lot of modern desktop PCs these days have touch screens, so even detecting touch support does not guarantee that it is a mobile device or tablet.