//区分设备 function judge_decice() { let ua =navigator.userAgent.toLowerCase(); if(/android|adr/gi.test(ua)) { return 'android'; }else if( /(i[^;]+;( U;)? CPU.+Mac OS X/gi.test(ua)) { return 'iphone'; }else if(/iPad/gi.test(ua)) { return 'ipad'; }else{ return 'unknow device'; } } //判断是不是pc function IsPC() { var userAgentInfo = navigator.userAgent; var Agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"]; var flag = true; for (var v = 0; v < Agents.length; v++) { if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; } } return flag; } //区分客户端 新浪微博为1,QQ客户端为2,微信低于6.0.2版本为3,高于6.0.2版本为4,其他为0。 function judge_client() { var ua = navigator.userAgent.toLowerCase(); if(ua.match(/weibo/i) == "weibo"){ console.log(1); }else if(ua.indexOf('qq/')!= -1){ console.log(2); }else if(ua.match(/MicroMessenger/i)=="micromessenger"){ var v_weixin = ua.split('micromessenger')[1]; v_weixin = v_weixin.substring(1,6); v_weixin = v_weixin.split(' ')[0]; if(v_weixin.split('.').length == 2){ v_weixin = v_weixin + '.0'; } if(v_weixin < '6.0.2'){ console.log(3); }else{ console.log(4); } }else{ console.log(0); } } //是否在微信打开 function isWeiXin(){ var ua = navigator.userAgent.toLowerCase(); if(ua.indexOf('micromessenger') != -1) { return true; } else { return false; } }