js判断是否是app,及版本号
Posted mosquito~
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js判断是否是app,及版本号相关的知识,希望对你有一定的参考价值。
export const Config = {}; Config.ua = navigator.userAgent.toLowerCase(); Config.isiOS=()=>{ return /(iphone|ipad|ipod|ios)/i.test(Config.ua) } Config.isAndroid=()=>{ return /(android)/i.test(Config.ua) } Config.isLaobaiAndroid = () => { return /laobaiapp android/.test(Config.ua); }; Config.isLaobaiiOS = () => { return /laobaiapp ios/.test(Config.ua) }; Config.isWeChat = () => { return /micromessenger/.test(Config.ua); }; Config.isQQ = () => { return /qq/.test(Config.ua); }; export default Config;
判断当前app的版本号
const getAppVerison = (expStr) => { if (expStr == null) return null; const ua = navigator.userAgent.toLowerCase(); const patt = new RegExp(expStr, "g"); let lastIndex = null; while ((patt.exec(ua)) != null) { lastIndex = patt.lastIndex } if (lastIndex == null) { return null } return ua.substr(lastIndex) };
对比app版本号,有时候版本不够需提示更新
export const compareVersionEle = (currVersion, targetVerison) => { if (!currVersion || !targetVerison) return false; const curr = currVersion.split(‘.‘); const target = targetVerison.split(‘.‘); for (let i = 0; i < curr.length; i++) { if (parseInt(curr[i]) > parseInt(target[i])) { return true } if (parseInt(curr[i]) < parseInt(target[i])) { return false } //相等继续 //parseInt(curr[i]) == parseInt(target[i]) continue } return true };
以上是关于js判断是否是app,及版本号的主要内容,如果未能解决你的问题,请参考以下文章
版本号对比方案及参考代码(Objective-C,Java,JavaScript)