如何在iOS7的useragent字符串中区分Chrome和Safari? [英] How does one differentiate between Chrome and Safari in an iOS7 useragent string?
本文介绍了如何在iOS7的useragent字符串中区分Chrome和Safari?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
navigator.userAgent.match()
的内容,iOS7上的Chrome和Safari将有所不同,iPad还是iPhone? 解决方案
var ua = navigator.userAgent;
var matches = ua.match(/^.*(iPhone | iPad)。*(OS \s [0-9])。*(CriOS | Version)\ / [。0-9] * 。\sMobile * $ / I);
if(!matches)console.log(不是我们想要的。);
else {
console.log(matches [1]);
if(matches [2] ==='OS 7')console.log(matches [2]);
else console.log('Not the right version。');
if(matches [3] ==='CriOS')console.log(Chrome);
else console.log(Safari);
}
参考:https://developers.google.com/chrome/mobile/docs/user-agent
Useragent details are sketchy, or I'm not looking in the right places.
What, in terms of a navigator.userAgent.match()
, would differentiate between Chrome and Safari on iOS7, iPad or iPhone?
解决方案
var ua = navigator.userAgent;
var matches = ua.match(/^.*(iPhone|iPad).*(OS\s[0-9]).*(CriOS|Version)\/[.0-9]*\sMobile.*$/i);
if (!matches) console.log("Not what we're looking for.");
else {
console.log(matches[1]);
if (matches[2] === 'OS 7') console.log(matches[2]);
else console.log('Not the right version.');
if (matches[3] === 'CriOS') console.log("Chrome");
else console.log("Safari");
}
Reference: https://developers.google.com/chrome/mobile/docs/user-agent
这篇关于如何在iOS7的useragent字符串中区分Chrome和Safari?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文