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?


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 (eg, J2ME), and broad classes of devices, such as "iPhone Tier" (iPhone/Android/WebOS) and smartphones.


尝试http://wurfl.sourceforge.net/获取设备功能。

链接地址: http://www.djcxy.com/p/1664.html

上一篇: 如何将当前工作目录设置为脚本的目录?

下一篇: 如何判断浏览器是否在使用JavaScript的触摸屏设备上?