jquery - 使用 Jquery 检测 Windows 平板电脑(触摸 Windows 设备)

标签 jquery touch device

我的网站运行一个脚本,该脚本仅对鼠标有用,并且必须在触摸屏上禁用,因为它不适用于鼠标。

所以为了解决这个问题,我使用这个:

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
        }

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

非常感谢您的帮助!

最佳答案

这应该可以。我已经在 ios safari、osx safari、windows IE、windows Chrome、windows Firefox、android 上进行了测试。

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

基本上,我们让浏览器确定是否存在触摸设备,然后查找触摸事件的浏览器特定实现。

Internet 浏览器 2011 年 9 月 10 日

navigator.msMaxTouchPoints

所有其他人:

'ontouchstart' in window

关于jquery - 使用 Jquery 检测 Windows 平板电脑(触摸 Windows 设备),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28860930/

相关文章:

ios - 在 Xcode 中按住并释放(声音)?

android - 如何检测硬件键盘的存在?

linux - 如何唯一标识一个 USB 设备?

Javascript ontouchstart/move/end - 得到奇怪的结果

javascript - 检测子元素动画

javascript - jquery如何获取选中的选项id

javascript - Bootstrap 弹出窗口中关于单引号/双引号的基本 HTML/JavaScript 混淆

C# Win 表单 : Detect last interaction (touch) and display confirmation box

video - UWP运行ffmpeg进程进行捕获

javascript - Jquery自动播放和自动播放下一首歌曲