javascript 如何识别用户代理是否是 Windows 8 平板电脑?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14226534/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to identify if user agent is windows 8 tablet?
提问by riship89
I have a web application. I my JavaScript, I am identifying devices by user agent string as follows:
我有一个网络应用程序。我的 JavaScript,我通过用户代理字符串识别设备,如下所示:
_android = navigator.userAgent.toLowerCase().indexOf("android");
_iOS = navigator.platform.indexOf("iPhone");
My task is to identify if device is win8 tablet or not?
我的任务是确定设备是否为 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?
我已经看过这个帖子了。但是,字符串“Windows NT”很可能会出现在所有 PC 浏览器的用户代理中。那么,我需要找出一种客户端方式来识别设备是否为 win8 平板电脑?
Any thoughts?
有什么想法吗?
回答by Dominic Hopton
You can't identify if it is a tablet or not, but you can identify if it has touchor not. This is the IE user agent here:
您无法识别它是否是平板电脑,但您可以识别它是否具有触摸功能。这是这里的 IE 用户代理:
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.
但是,如果您只是想识别触摸功能,则应该使用功能检测而不是用户代理嗅探。
回答by Ra.
User-agent string (Windows) : http://msdn.microsoft.com/en-us/library/ie/hh920767(v=vs.85).aspx
用户代理字符串(Windows):http: //msdn.microsoft.com/en-us/library/ie/hh920767( v=vs.85) .aspx