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

孤街醉人 提交于 2019-12-29 07:17:10

问题


Useragent details are sketchy, or I'm not looking in the right places.

What, in terms of a navigator.userAgent.match(), would differentiate between Chrome and Safari on iOS7, iPad or iPhone?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/19106645/how-does-one-differentiate-between-chrome-and-safari-in-an-ios7-useragent-string

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