The easiest way to detect touch-capable browsers is to check for the presence of touch events. It is no 100% solution, but has by far the best cost-benefit ratio. (Know that this does not detect touch devices, but browsers.)
Javascript
var isTouchDevice = 'ontouchstart' in window
Coffeescript
isTouchDevice = 'ontouchstart' of window
On the difference between the Javascript and the Coffeescript version, see Beware: Coffeescript "in" is not the Javascript "in".
Posted by Dominik Schöler to makandra dev (2015-02-18 13:30)