2

用户代理的细节是粗略的,或者我没有在正确的地方寻找。

就 a 而言navigator.userAgent.match(),iOS7、iPad 或 iPhone 上的 Chrome 和 Safari 有什么区别?

4

2 回答 2

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

于 2013-10-01T04:29:17.413 回答
1

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

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

于 2013-10-01T02:47:51.517 回答