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

╄→гoц情女王★ 提交于 2019-11-29 08:43:39
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

Not sure about iOS, never had a device, but under Windows Chrome has a window.chrome object defined. Check for it existence and if it's there - you're in Chrome.

If similar approach works under iOS (I think it should) then u don't need to check UserAgent.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!