企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
## 前言 浏览器ua常识作为一名前端是必备的,因为有些ua是有特殊问题的,而今天分享的主要是通过js的方式来判断ua,以及根据ua来做一些具体的处理。 那么一般情况下,我们会针对那些ua特殊处理呢?特殊的具体:ie,手机端微信,app环境,谷歌环境,sari,opera环境,特殊情况下,如果我们的代码or产品对浏览器的版本有要求也需要进行严谨的判断并引导用户用正确的浏览器打开或者在特殊情况下,代码or产品特殊处理。 ## js获取浏览器ua `var ua =navigator.userAgent.toLowerCase();` ## 浏览器ua统计 | 客户端类型 | 代码 | | --- | --- | | 手机微信 |mozilla/5.0 (iphone; cpu iphone os 9_1 like mac os x) applewebkit/601.1.46 (khtml, like gecko) version/9.0 mobile/13b143 safari/601.1 wechatdevtools/0.7.0 | | pc版微信(windows) | mozilla/5.0 (windows nt 6.1; wow64) applewebkit/537.36 (khtml, like gecko) chrome/39.0.2171.95 safari/537.36 micromessenger/6.5.2.501 nettype/wifi windowswechat | | mac版safari | mozilla/5.0 (macintosh; intel mac os x 10_12_5) applewebkit/603.2.4 (khtml, like gecko) version/10.1.1 safari/603.2.4 | | safari iOS 4.33 – iPhone | User-Agent:Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5 | | safari iOS 4.33 – iPod Touch | Mozilla/5.0 (iPod; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5 | | safari iOS 4.33 – iPad | Mozilla/5.0 (iPad; U; CPU OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5 | | BlackBerry | Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.337 Mobile Safari/534.1+ | | UC标准| NOKIA5700/ UCWEB7.0.2.37/28/999 | | IE浏览器 | Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; | | 360浏览器(判断字段是360se) | Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; InfoPath.2; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; 360SE) | | 搜狗浏览器 | Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; SE 2.X MetaSr 1.0; SE 2.X MetaSr 1.0; .NET CLR 2.0.50727; SE 2.X MetaSr 1.0) | | Chrome | Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_0) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11 | | Safari(pc) |Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50 | | Safari(移动设备) | Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5 | | Firefox 判断标准是Firefox字段| Mozilla/5.0 (Androdi; Linux armv7l; rv:5.0) Gecko/ Firefox/5.0 fennec/5.0| 备注: mac版pc端微信实际是跳转到系统的sari,自己没有微信端的浏览器。