如何在iOS7用户代理字符串中区分Chrome和Safari

How does one differentiate between Chrome and Safari in an iOS7 useragent string?

本文关键字:Chrome Safari 中区 字符串 iOS7 用户代理      更新时间:2023-09-26

用户代理的详细信息很粗略,或者我没有在正确的地方寻找。

navigator.userAgent.match()而言,在iOS7,iPad或iPhone上区分Chrome和Safari是什么?

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

不确定iOS,从未有过设备,但在Windows Chrome下定义了window.chrome对象。检查它是否存在,如果它在那里 - 你在 Chrome 中。

如果类似的方法在iOS下有效(我认为应该),那么您不需要检查UserAgent。