Detect touch devices in JavaScript

Today I’m writing about a JavaScript snippet that I use to detect if the device has a touchscreen.

This code won’t work on some old version of Chrome on Windows 8/8.1 because at this time the browser was supporting some touch features on non-touch devices. You can read about it here :

You have to be aware that it is very difficult to detect if a device has a touchscreen because depending of the browser and operating system, the touch features can be implemented on a non-touch device. So I tested my snippet with Safari on iOS, Firefox, Chrome and Internet Explorer 10/11 on Windows 8.1 and Windows 10 technical preview but I can’t tell for how long it will keep working.

You can test this snippet thanks to this fiddle :

Leave a Reply

Your email address will not be published. Required fields are marked *