Playzare
Playzare

Reputation: 93

Detecting Windows Tablet (touch windows devices) with Jquery

My site run a script which is only useful with the mouse, and which have to be disable on touch screen because it don't work with them.

So to solve it i use this :

var deviceAgent = navigator.userAgent.toLowerCase();

var isTouchDevice = Modernizr.touch || 
(deviceAgent.match(/(iphone|ipod|ipad)/) ||
deviceAgent.match(/(android)/)  || 
deviceAgent.match(/(iemobile)/) || 
deviceAgent.match(/iphone/i) || 
deviceAgent.match(/ipad/i) || 
deviceAgent.match(/ipod/i) || 
deviceAgent.match(/blackberry/i) || 
deviceAgent.match(/bada/i));

if (!isTouchDevice) {
//my fonction
        }

But this code doesn't detect other touch devices mainly like windows tablets (i have one), and i would like to detect with deviceAgent or anything else the other touch devices, or all touch devices if it's possible.

Thank you very much for your help !

Upvotes: 2

Views: 1560

Answers (1)

Arctelix
Arctelix

Reputation: 4576

This should do it.. I have tested on ios safari, osx safari, windows IE, windows Chrome, windows Firefox, android.

var isTouchDevice    = 'ontouchstart' in window || (navigator.msMaxTouchPoints>0);

Basically, we let the browser determine if there is a touch device and then look for the browser specific implementations of touch events.

Internet explorer 9/10/11

navigator.msMaxTouchPoints

All others:

'ontouchstart' in window

Upvotes: 2

Related Questions