Frage

Is there a way to detect if the user is on a touchscreen device? I want to change some HTML/jquery based on that fact (more specifically, jquery capSlide to show caption on touchscreen devices while hiding it on desktop). What would be the easiest way to accomplish this?

War es hilfreich?

Lösung

This one-liner should suffice.

var is_touch_device = 'ontouchstart' in document.documentElement;

Taken from this Stack Overflow answer here: https://stackoverflow.com/a/6447935/1585455

Your conditional should look something like this:

if(is_touch_device) { /* your code */ }
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top