简体   繁体   English

是否可以通过JavaScript或HTTP标头检测*“移动设备”的类型?

[英]Possible to detect the *type of mobile device* via javascript or HTTP Headers?

I've got a request from a customer to automatically detect the type of mobile device (not the browser, the type. ex: Moto Q, Blackjack II, etc.) and automatically select the device from a drop down with a list of supported devices. 我收到客户的要求,以自动检测移动设备的类型(而不是浏览器,类型,例如:Moto Q,Blackjack II等),并从下拉列表中自动选择支持的设备设备。

So far I've found that the HTTP Headers (submitted by mobile IE) contain information such as 到目前为止,我发现HTTP标头(由移动IE提交)包含以下信息:

  • Resolution 解析度
  • UA-CPU (i've seen ARM from WM 2003 and x86 from WM5) UA-CPU(我从WM 2003看过ARM,从WM5看过x86)
  • User Agent (which basically just says Windows CE) 用户代理(基本上只是说Windows CE)

The only thing I can think of right now is possibly using a combination of the resolution/cpu and making a "best guess" 我现在唯一想到的可能是结合使用分辨率/ cpu和做出“最佳猜测”

Any thoughts? 有什么想法吗?

You may want to have a look at WURFL, here: http://wurfl.sourceforge.net/ . 您可能想在这里查看WURFL: http ://wurfl.sourceforge.net/。

From the site: 从站点:

So... What is WURFL? 那么...什么是WURFL? The WURFL is an XML configuration file which contains information about capabilities and features of many mobile devices. WURFL是一个XML配置文件,其中包含有关许多移动设备的功能和特性的信息。

The main scope of the file is to collect as much information as we can about all the existing mobile devices that access WAP pages so that developers will be able to build better applications and better services for the users. 该文件的主要范围是收集有关我们访问WAP页面的所有现有移动设备的尽可能多的信息,以便开发人员能够为用户构建更好的应用程序和更好的服务。

What exactly does the customer mean by "supported". 客户所说的“受支持”到底是什么意思。 Surely it means that the phone in question supports the web application and it's inner functionality - wouldn't it be better then to forget device detection and simply focus on detecting those capabilities required for the app to function properly? 当然,这意味着所讨论的电话支持Web应用程序及其内部功能-然后忘记设备检测并仅仅专注于检测应用程序正常运行所需的那些功能,岂不是更好吗? For example, if my mobile website requires Ajax to work then instead of listing all the devices which are said to "support Ajax" I could do some simple object detection to find out for myself. 例如,如果我的移动网站要求Ajax可以工作,那么与其列出所有被称为“支持Ajax”的设备,不如我可以做一些简单的对象检测来为自己找出答案。

Device detection, just like browser detection is unreliable. 就像浏览器检测一样,设备检测也不可靠。 Yes, it's possible but I wouldn't recomend it... on a project I've done we used the User Agent string to detect various devices. 是的,有可能,但是我不建议这样做……在我完成的项目中,我们使用了用户代理字符串来检测各种设备。 The indexOf javaScript method came in handy! indexOf javaScript方法派上用场了! :) :)

另一个快速简便的解决方案是Apache Mobile Filter: http : //www.apachemobilefilter.org

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM