With all kinds of odd strange ua detect the browser

Project requirements can only open a page in safari ios end, the other not.
Had only identified the ua ipad, iphone + safari number at the end, it was not found, and chrome can not be distinguished.
ios end of the safari does not seem to be all browsers and other key distinction between a keyword or features, can only try to rule out other browsers through a process of elimination.
I checked around and found detection methods predecessors summary, the test is feasible, recorded as follows:

var browserName = "Other";
    var ua = window.navigator.userAgent;
    browserRegExp = {
      Sogou : /SE\s2\.X|SogouMobileBrowser/,
      Explorer2345 : /2345Explorer|2345chrome|Mb2345Browser/,
      Liebao : /LBBROWSER/,
      QQBrowser : /QQBrowser/,
      Baidu : /BIDUBrowser|baidubrowser|BaiduHD/,
      UC : /UBrowser|UCBrowser|UCWEB/,
      MiuiBrowser : /MiuiBrowser/,
      Wechat : /MicroMessenger/,
      MobileQQ : /Mobile\/\w{5,}\sQQ\/(\d+[\.\d]+)/,
      Shoujibaidu : /baiduboxapp/,
      Firefox : /Firefox/,
      Maxthon : /Maxthon/,
      Se360 : /360SE/,
      Ee360 : /360EE/,
      TheWorld : /TheWorld/,
      Weibo : /__weibo__/,
      NokiaBrowser : /NokiaBrowser/,
      Opera : /Opera|OPR\/(\d+[\.\d]+)/,
      Edge : /Edge/,
      AndroidBrowser : /Android.*Mobile\sSafari|Android\/(\d[\.\d]+)\sRelease\/(\d[\.\d]+)\sBrowser\/AppleWebKit(\d[\.\d]+)/i,
      IE : /Trident|MSIE/,
      Chrome : /Chrome|CriOS/,
      Safari : /Version[|\/]([\w.]+)(\s\w.+)?\s?Safari|like\sGecko\)\sMobile\/\w{3,}$/,
    };
    for (var i in browserRegExp) {
      if (browserRegExp[i].exec(ua)) {
        browserName = i;
        break;
      }
    }
    if (typeof window.ga !== 'undefined') {
      window.ga('set', 'dimension3', browserName);
    }

Guess you like

Origin www.cnblogs.com/xiaoyuchen/p/11326225.html