【问题标题】:WindowsPhone which user agent is correct?WindowsPhone 哪个用户代理是正确的?
【发布时间】:2015-02-16 15:57:43
【问题描述】:

有人知道为什么 php 和 jscript 输出不同的用户代理吗?

还有,哪一个是正确的?

PHP

<?php print_r($_SERVER['HTTP_USER_AGENT']); ?>

输出: Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; Microsoft; Lumia535) like iPhone OS7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari /537)

jScript

alert(navigator.userAgent);

输出: Mozilla/5.0(兼容;MSIE 9.0;Windows Phone OS 7.5;Trident/5.0;IEMobile/9.0;微软;Lumia 535

【问题讨论】:

  • 你用哪个浏览器测试过这个?你读过this 功能检测比使用Modernizr 之类的库的用户代理检测更重要
  • 在 Lumia 535 上使用 Internet Explorer 测试

标签: javascript php windows-phone


【解决方案1】:

在我们的门户中,我们通过 UAS 检测到呼叫设备。我检测到 WP 8.1 用户代理字符串存在一些问题。 对于带有 IE 的 WP,设置为通过 Internet 移动,我收到“有意义的”UAS:

Mozilla/5.0(移动;Windows Phone 8.1;Android 4.0;ARM;Trident/7.0; 触碰;房车:11.0; IEMobile/11.0;诺基亚; Lumia 930) 喜欢 iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537

其中,如果 IE 移动设置为“桌面”或通过 Intranet 调用门户,我会收到:

Mozilla/5.0(Windows NT 6.2;ARM;Trident/7.0;Touch;rv:11.0; WP桌面; Lumia 930) 像壁虎

所以.. 效果是,我们的门户网站向 iOS 显示了移动页面,而不是向 WP 显示了移动页面。 解决方法是在查询 iPhone 之前向 UAS 查询“Windows Phone”。 似乎 MS 尝试以这种方式被检测为移动设备(如果页面仅查询 iOS 和 Android 设备),这不是很好。
因此,没有“一个”正确的UAC,你必须支持多个......

【讨论】:

    猜你喜欢
    • 2011-05-30
    • 2023-03-30
    • 2013-04-27
    • 1970-01-01
    • 1970-01-01
    • 2019-08-18
    • 2019-10-27
    • 2019-06-19
    • 2020-02-24
    相关资源
    最近更新 更多