In the past, when detecting whether a device supports touch events in JavaScript, we could do something like this:
var touch_capable = ('ontouchstart' in document.documentElement);
However, Google Chrome (17.x.x+) returns true
for the above check, even if the underlying device does not support touch events. For example, running the above code on Windows 7 returns true, and thus if we combine it with something like:
var start_evt = (touch_capable) ? 'ontouchstart' : 'onmousedown';
On Google Chrome, the event is never fired since we're binding to ontouchstart
. In short, does anyone know a reliable way to circumvent this? I am currently running the following check:
var touch_capable = ('ontouchstart' in document.documentElement && navigator.userAgent.toLowerCase().indexOf('chrome') == -1)
Which is far from ideal...