UNPKG

tbm-ua

Version:

UA检测

95 lines (75 loc) 5.43 kB
# tbm-ua UA 组件,判断不同的平台和设备及容器 [demo 地址](http://site.alibaba.net/party/tbm-ua) ## Install ```cli $ tnpm i @ali/tbm-ua --save ``` ## Usage ```html <h2>UA用法展示</h2> <button id="btn">判断该platform</button> <button id="btn1">该platform是淘宝么</button> ``` ```javascript import ua from '@ali/tbm-ua'; var oBtn = document.querySelector('#btn'); var oBtn1 = document.querySelector('#btn1'); oBtn.addEventListener( 'click', function () { alert(ua); }, false ); oBtn1.addEventListener( 'click', function () { if (ua.isTB) { alert('是'); } else { alert('不是'); } }, false ); //做个示范 判断平台是不是淘宝 //if(ua.isTB){} ``` ## API ##### 若 UA 匹配成功,则返回匹配后的数组,若匹配失败,则返回 null。 ##### 若 UA 匹配成功,则返回匹配后的数组,若匹配失败,则返回 null。 | 平台 | Api 名称 | 返回值类型 | 备注 | | ---------------- | ---------- | ------------------------- | ------------------------------------------------------------------------------------ | | UC 容器 U4 内核 | isUCU4 | True: <Array>/False: null | | | UC 容器 U3 内核 | isUCU3 | True: <Array>/False: null | | | IOS | isIOS | True: <Array>/False: null | | | Android | isAndroid | True: <Array>/False: null | | | WindVane 容器 | isWindVane | True: <Array>/False: null | 需组合 `window.WindVane && window.WindVane.isAvailable` ; 手淘专有 API 应判断` isTB` | | WindVane 和 钱包 | isMV | True: <Array>/False: null | DY & WindVane | | TBMovie 和钱包 | isDY | True: <Array>/False: null | DY & Nebula | | AliTrip | isAT | True: <Array>/False: null | 飞猪 | | 淘宝 | isTB | True: <Array>/False: null | 手淘 | | 钱包 | isAP | True: <Array>/False: null | 钱包客户端 | | 口碑 | isKB | True: <Array>/False: null | 口碑客户端 | | 淘票票专业版 | isMVP | True: <Array>/False: null | | | 微博 | isWB | True: <Array>/False: null | | | 微博电影 | isWBM | True: <Array>/False: null | | | 高德 | isGD | True: <Array>/False: null | | | 虾米音乐 | isXM | True: <Array>/False: null | | | 优酷 | isYK | True: <Array>/False: null | | | 神马搜索 | isSM | True: <Array>/False: null | | | 搜狗 | isSG | True: <Array>/False: null | | | 大麦 | isDM | True: <Array>/False: null | | | 天猫 | isTM | True: <Array>/False: null | | | 快应用 | isQuickApp | True: <Array>/False: null | | | 微信 H5 | isWX | True: <Array>/False: null | 仅匹配微信 H5,若是微信小程序中的 webview,则返回 null | | 微信小程序 | isWXApp | True: <Array>/False: null | 仅匹配微信小程序 | ## FAQ UA 组件只提供不同平台和设备及容器的判断,不涉及容器版本的判断,如果需要判断容器版本做特殊的处理,可以参考如下的使用方法: ```javascript // 主客版本大于 7.9.0 做特殊处理 UA.isDY && TBM.getVersion(TBM.clientInfo['client.version']) >= TBM.getVersion('7.9.0')) // 钱包版本大于 9.5.3 做特殊处理 UA.isAP && TBM.clientInfo && TBM.getVersion(TBM.clientInfo['client.version']) >= TBM.getVersion('9.5.3'); ```