Detecting touch screen devices with Javascript Detecting touch screen devices with Javascript android android

Detecting touch screen devices with Javascript


var isTouchDevice = 'ontouchstart' in document.documentElement;

Note: Just because a device supports touch events doesn't necessarily mean that it is exclusively a touch screen device. Many devices (such as my Asus Zenbook) support both click and touch events, even when they doen't have any actual touch input mechanisms. When designing for touch support, always include click event support and never assume any device is exclusively one or the other.


Found testing for window.Touch didn't work on android but this does:

function is_touch_device() {  return !!('ontouchstart' in window);}

See article: What's the best way to detect a 'touch screen' device using JavaScript?


+1 for doing hover and click both. One other way could be using CSS media queries and using some styles only for smaller screens / mobile devices, which are the ones most likely to have touch / tap functionality. So if you have some specific styles via CSS, and from jQuery you check those elements for the mobile device style properties you could hook into them to write you mobile specific code.

See here: http://www.forabeautifulweb.com/blog/about/hardboiled_css3_media_queries/