如何检测没有铬的移动游猎?

时间:2015-01-13 21:49:06

标签: mobile safari

我正在尝试了解当用户在移动版Safari中打开我的网站时如何检测。 Chrome和Safari有完全相同的参数: Chrome“Mozilla / 5.0(iPad; CPU OS 8_1_2,如Mac OS X)AppleWebKit / 600.1.4(KHTML,类似Gecko)版本/ 8.0 Mobile / 12B440 Safari / 600.1.4” Safari“Mozilla / 5.0(iPad; CPU OS 8_1_2,如Mac OS X)AppleWebKit / 600.1.4(KHTML,类似Gecko)版本/ 8.0 Mobile / 12B440 Safari / 600.1.4” 有没有办法只检测移动游猎?

1 个答案:

答案 0 :(得分:1)

Chrome for developers网站声明:

  

适用于iOS的Chrome中的UA与Mobile Safari用户代理相同,使用CriOS /而不是版本/< VersionNum>

所以正确的使用者检查将是:

 var ua = navigator.userAgent;
 if (ua.match(/(iPod|iPhone|iPad)/) !== null && ua.match(/AppleWebKit/) !== null && ua.search('CriOS') < 0) {
     alert("You are using Mobile Safari!");
 } else {
     alert("Whatever this is, it's not Mobile Safari...");
 }

这里是小提琴 - https://jsfiddle.net/h8j9n2m5/1/。在iPad iOS 7.0.4上查看自己,Mobile Safari 7.0就像魅力一样:)

相关问题