how to identify if user agent is windows 8 tablet?(如何识别用户代理是否是 Windows 8 平板电脑?)
问题描述
我有一个网络应用程序.我是我的 JavaScript,我通过用户代理字符串来识别设备,如下所示:
I have a web application. I my JavaScript, I am identifying devices by user agent string as follows:
_android = navigator.userAgent.toLowerCase().indexOf("android");
_iOS = navigator.platform.indexOf("iPhone");
我的任务是识别设备是否是win8平板电脑?
My task is to identify if device is win8 tablet or not?
我已经看过这篇文章.但是,字符串Windows NT"很可能出现在所有 PC 浏览器的 useragent 中.那么,我需要找出一种客户端方法来识别设备是否是 win8 平板电脑?
I have already seen this post. But, the string "Windows NT" is likely to appear in useragent on all the PC browsers. So, I need to find out a client side way of identifying if device is win8 tablet?
有什么想法吗?
推荐答案
你无法识别它是否是平板电脑,但你可以识别它是否有touch.这是这里的 IE 用户代理:
You can't identify if it is a tablet or not, but you can identify if it has touch or not. This is the IE user agent here:
Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0; Touch)
只有在有触摸的情况下才会出现最后的触摸.
The touch at the end is only present if touch is.
然而,如果你只是想识别触摸功能,你应该使用特征检测而不是用户代理嗅探.
However, if you are just trying to identify touch capabilities, you should use feature detection rather than user agent sniffing.
这篇关于如何识别用户代理是否是 Windows 8 平板电脑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何识别用户代理是否是 Windows 8 平板电脑?


基础教程推荐
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- 直接将值设置为滑块 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01