Reputation: 9855
I'm trying to use javascript to detect if my visitor is on a touch device or not.
I have the following...
function is_touch_device() {
return 'ontouchstart' in window || 'onmsgesturechange' in window;
}
The above works fine apart from ie11 is returning true, that it is a touch device when in reality it isnt. Has anybody experienced this before?
Upvotes: 4
Views: 1977
Reputation: 11468
The following code snippet might help:
function is_touch_device() {
return (('ontouchstart' in window)
|| (navigator.maxTouchPoints > 0)
|| (navigator.msMaxTouchPoints > 0));
//navigator.msMaxTouchPoints for microsoft IE backwards compatibility
}
Upvotes: 8