用户代理的详细信息很粗略,或者我没有在正确的地方寻找。
就navigator.userAgent.match()
而言,在iOS7,iPad或iPhone上区分Chrome和Safari是什么?
var ua = navigator.userAgent;
var matches = ua.match(/^.*(iPhone|iPad).*(OSs[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
不确定iOS,从未有过设备,但在Windows Chrome下定义了window.chrome
对象。检查它是否存在,如果它在那里 - 你在 Chrome 中。
如果类似的方法在iOS下有效(我认为应该),那么您不需要检查UserAgent。