粗暴的细节是粗略的,或者我找不到合适的地方。
根据navigator.userAgent.match()
,iOS7,iPad或iPhone上的Chrome和Safari有什么区别?
答案 0 :(得分:10)
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");
}
参考:https://developers.google.com/chrome/mobile/docs/user-agent
答案 1 :(得分:1)
不确定iOS,从未有过设备,但在Windows Chrome下定义了window.chrome
对象。检查它是否存在,如果它存在 - 你在Chrome中。
如果类似的方法在iOS下工作(我认为应该),那么你不需要检查UserAgent。