移动端:H5判断浏览器类型

先获取浏览器信息

let ua = navigator.userAgent.toLowerCase(); // 这里将所有字母转小写
console.log(ua);

我们看看移动端不同浏览器的信息(部分举例,个人见解):

浏览器 ua展示的信息
safari浏览器                             mozilla/5.0 (iphone; cpu iphone os 13_5_1 like mac os x) applewebkit/605.1.15 (khtml, like gecko) version/13.1.1 mobile/15e148 safari/604.1
微信浏览器-安卓 mozilla/5.0 (linux; android 10; bkl-al00 build/huaweibkl-al00; wv) applewebkit/537.36 (khtml, like gecko) version/4.0 chrome/77.0.3865.120 mqqbrowser/6.2 tbs/045227 mobile safari/537.36 mmwebid/8185 micromessenger/7.0.17.1720(0x27001137) process/tools wechat/arm64 nettype/wifi language/zh_cn abi/arm64
微信浏览器-ios mozilla/5.0 (iphone; cpu iphone os 13_5_1 like mac os x) applewebkit/605.1.15 (khtml, like gecko) mobile/15e148 micromessenger/7.0.14(0x17000e29) nettype/wifi language/zh_cn
QQ浏览器-安卓 mozilla/5.0 (linux; u; android 10; zh-cn; bkl-al00 build/huaweibkl-al00) applewebkit/537.36 (khtml, like gecko) version/4.0 chrome/66.0.3359.126 mqqbrowser/10.6 mobile safari/537.36
QQ浏览器-ios mozilla/5.0 (iphone; cpu iphone os 13_5_1 like mac os x) applewebkit/604.3.5 (khtml, like gecko) version/13.0 mqqbrowser/10.5.3 mobile/15b87 safari/604.1 qbwebviewua/2 qbwebviewtype/1 wktype/1
UC浏览器-安卓 mozilla/5.0 (linux; u; android 9; zh-cn; v1816a build/pkq1.180819.001) applewebkit/537.36 (khtml, like gecko) version/4.0 chrome/78.0.3904.108 ucbrowser/13.0.4.1084 mobile safari/537.36
UC浏览器-ios mozilla/5.0 (iphone; cpu iphone os 13_5_1 like mac os x; zh-cn) applewebkit/537.51.1 (khtml, like gecko) mobile/17f80 ucbrowser/13.0.4.1340 mobile aliapp(tunionsdk/0.1.20.3)
vivo自带浏览器 mozilla/5.0 (linux; android 9; v1816a build/pkq1.180819.001; wv) applewebkit/537.36 (khtml, like gecko) chrome/62.0.3202.84 mobile safari/537.36 vivobrowser/8.1.14.2
百度-安卓 mozilla/5.0 (linux; android 9; v1816a build/pkq1.180819.001; wv) applewebkit/537.36 (khtml, like gecko) version/4.0 chrome/76.0.3809.89 mobile safari/537.36 t7/11.23 sp-engine/2.17.0 flyflow/4.18.0.31 lite baiduboxapp/4.18.0.31 (baidu; p1 9)
百度-ios mozilla/5.0 (iphone; cpu iphone os 13_5_1 like mac os x) applewebkit/605.1.15 (khtml, like gecko) mobile/15e148 sp-engine/2.21.0 main%2f1.0 baiduboxapp/11.25.0.16 (baidu; p2 13.5.1) nabar/1.0
猎豹-安卓 mozilla/5.0 (linux; u; android 9; zh-cn; v1816a build/pkq1.180819.001) applewebkit/535.19 (khtml, like gecko) version/4.0 liebaofast/5.21.0 mobile safari/535.19
谷歌-安卓 mozilla/5.0 (linux; android 9; v1816a) applewebkit/537.36 (khtml, like gecko) chrome/70.0.3538.110 mobile safari/537.36
谷歌-ios mozilla/5.0 (iphone; cpu iphone os 13_5 like mac os x) applewebkit/605.1.15 (khtml, like gecko) crios/84.0.4147.71 mobile/15e148 safari/604.1
夸克-安卓 mozilla/5.0 (linux; u; android 9; zh-cn; v1816a build/pkq1.180819.001) applewebkit/537.36 (khtml, like gecko) version/4.0 chrome/57.0.2987.108 quark/4.2.1.138 mobile safari/537.36
夸克-ios mozilla/5.0 (iphone; cpu iphone os 13_5_1 like mac os x; zh-cn) applewebkit/601.1.46 (khtml, like gecko) mobile/17f80 quark/4.2.2.1053 mobile
欧朋-安卓 mozilla/5.0 (linux; u; android 9; zh-cn; v1816a build/pkq1.180819.001) applewebkit/537.36 (khtml, like gecko) version/4.0 opr/12.45.0.1 mobile safari/537.36
欧朋-ios mozilla/5.0 (iphone; cpu iphone os 13_5_1 like mac os x) applewebkit/605.1.15 (khtml, like gecko) mobile/15e148
360-安卓 mozilla/5.0 (linux; android 9; v1816a build/pkq1.180819.001; wv) applewebkit/537.36 (khtml, like gecko) version/4.0 chrome/73.0.3683.121 mobile safari/537.36
360-ios mozilla/5.0 (iphone; cpu iphone os 13_5_1 like mac os x) applewebkit/605.1.15 (khtml, like gecko) mobile/15e148
搜狗-ios mozilla/5.0 (iphone; cpu iphone os 13_5_1 like mac os x) applewebkit/605.1.15 (khtml, like gecko) mobile/15e148 sogoumobilebrowser/5.21.8

捡几个常用浏览器来说说:

  1. 微信浏览器:
let isWxBrowser = ua.indexOf('micromessenger') !== -1
  1. Safari浏览器:
// 那么多浏览器都有safari字符串,我靠!
// 1. 有Safari字眼,
// 2. 剔除‘browser’字眼
// 3. 剔除‘android’字眼,可是谷歌ios。。。。
let isSafari= ua.indexOf('safari') !== -1 && ua.indexOf('browser') === -1  && ua.indexOf('android') === -1
  1. QQ浏览器:
let isqqBrowser = ua.indexOf('mqqbrowser') !== -1
  1. UC浏览器:
let isUc= ua.indexOf('ucbrowser') !== -1
  1. 百度浏览器(这应该是百度App):
let isBaidu = ua.indexOf('baiduboxapp') !== -1
  1. 360浏览器:
//?我考错了?

你可能感兴趣的:(JavaScript,移动端,移动端浏览器判断,safari浏览器判断,微信浏览器判断,UC浏览器判断,qq浏览器判断)