Detect Touch devices using JavaScript

The following function allows the detection of touch devices (smartphones, tablets, …) using JavaScript. As an example, this allows you to offer certain actions on a website or web application only for appropriate devices like disabling hover effects for touch devices.

function isTouchDevice() {
	return ('ontouchstart' in window);
}