Liam
Liam

Reputation: 9855

Detect if touch device with ie11 using javascript

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

Answers (1)

Jack_of_All_Trades
Jack_of_All_Trades

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

Related Questions