1.识别手机平台是IOS还是安卓
/** * [isMobile 判断平台] * @param test: 0:iPhone 1:Android */ function ismobile(test) { var u = navigator.userAgent, app = navigator.appVersion if (/AppleWebKit.*Mobile/i.test(navigator.userAgent) || ( /MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/ .test(navigator.userAgent))) { if (window.location.href.indexOf("?mobile") <0) { try { if (/iPhone|mac|iPod|iPad/i.test(navigator.userAgent)) { return "0:苹果"; } else { return "1:安桌"; } } catch (e) { // alert(e); } } } else if (app.indexOf("iPad") > -1|| app.indexOf("iPhone") > -1) { return "0:苹果"; } else { return "1:安桌"; } };
ismobile(1)
2.识别是否微信内置浏览器
function isWeiXin() { var ua = window.navigator.userAgent.toLowerCase(); // console.log(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 if (ua.match(/MicroMessenger/i) == "micromessenger") { return true; } else { return false; } }
3.识别移动终端手机品牌
function judgeBrand(sUserAgent) { // var isIphOne= sUserAgent.match(/iphone/i) == "iphone"; var isHuawei = sUserAgent.match(/huawei/i) == "huawei"; var isHOnor= sUserAgent.match(/honor/i) == "honor"; var isOppo = sUserAgent.match(/oppo/i) == "oppo"; var isOppoR15 = sUserAgent.match(/pacm00/i) == "pacm00"; var isVivo = sUserAgent.match(/vivo/i) == "vivo"; var isXiaomi = sUserAgent.match(/mis/i) == "mi "; var isXiaomi2s = sUserAgent.match(/mixs/i) == "mix "; var isRedmi = sUserAgent.match(/redmi/i) == "redmi"; var isSamsung = sUserAgent.match(/sm-/i) == "sm-"; var isMeizu = sUserAgent.match(/meizu/i) == "meizu"; // if (isIphone) { // return "iphone"; // } else if (isHuawei || isHonor) { return "huawei"; } else if (isOppo || isOppoR15) { return "oppo"; } else if (isVivo) { return "vivo"; } else if (isXiaomi || isRedmi || isXiaomi2s) { return "xiaomi"; } else if (isSamsung) { return "samsung"; } else if (isMeizu) { return "meizu"; } else { return ""; } } var brand = judgeBrand(navigator.userAgent.toLowerCase());