使用Jquery检测Windows Tablet(触摸Windows设备) [英] Detecting Windows Tablet (touch windows devices) with Jquery

查看:106
本文介绍了使用Jquery检测Windows Tablet(触摸Windows设备)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站运行的脚本只对鼠标有用,必须在触摸屏上禁用,因为它不适用于它们。

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
        }

但是这段代码没有检测到其他触摸设备,主要是像平板电脑(我有一个),我想用deviceAgent或其他任何其他触摸设备或所有触摸设备检测,如果可能的话。

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.

非常感谢你的帮助!

推荐答案

这应该我已经测试了ios safari,osx safari,windows IE,windows Chrome,windows Firefox,android。

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

Internet explorer 9/10/11

navigator.msMaxTouchPoints

所有其他:

'ontouchstart' in window

这篇关于使用Jquery检测Windows Tablet(触摸Windows设备)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆