Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I tell whether a browser is on a touchscreen device with JavaScript?

I know this is a bit of perennial question, but here goes: I want to know whether the device my site is being accessed with is a touchscreen. That means phones and iPads, of course, which are individually detectable, but also other touchscreens that may well be running flavors of Windows. Any chance of determining the presence or absence of a mouse on those?

Let's say I'm willing to use a large JavaScript library like Modernizr. Will that help any?

like image 829
Trevor Burnham Avatar asked Jun 29 '10 02:06

Trevor Burnham


1 Answers

You might want to look into MobileESP. Not touchscreens only, but it at least gives you some detection capabilities. From their page:

The MobileESP project seeks to provide web site developers an easy-to-use and lightweight API for detecting whether visitors are using a mobile device, and if so, what kind. The APIs provide simple boolean results for popular individual device OS categories (such as iPhone, BlackBerry, Symbian S60, and Windows Mobile), device capabilities (e.g., J2ME), and broad classes of devices, such as "iPhone Tier" (iPhone/Android/WebOS) and smartphones.

like image 113
Gert Grenander Avatar answered Sep 20 '22 15:09

Gert Grenander