js判断设备、浏览器类型
function getAppVersion(){
var browser = {
versions: function () {
var u = navigator.userAgent,
app = navigator.appVersion,
ua = navigator.userAgent.toLowerCase();
//移动终端浏览器版本信息
return {
mobile: !!u.match(/AppleWebKit.*Mobile.*/),
ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),
android: ( u.indexOf('Android') > -1 || u.indexOf('Linux') > -1 ? "Android" : false ), //android终端或uc浏览器
iPhone: (u.indexOf('iPhone') > -1 ? "iPhone" : false ), //是否为iPhone或者QQHD浏览器
wechat: ( ua.match(/MicroMessenger/i) == "micromessenger" ? "micromessenger" : false ),
winPhone: (u.indexOf('Windows Phone') > -1 ? "winPhone" : false ) //winPhone 手机
};
}(),
language: (navigator.browserLanguage || navigator.language).toLowerCase()
}
if(browser.versions.mobile){
if(browser.versions.wechat){
return "micromessenger";
}
if(browser.versions.android && !browser.versions.wechat){
return "Android" ;
}
if(browser.versions.iPhone && !browser.versions.wechat){
return "iPhone" ;
}
}else{
if(browser.versions.wechat){
return "pcmicromessenger";
}
}
}
2、判断浏览器类型
function getExplorer(){
var userAgent = navigator.userAgent;
var isOpera = userAgent.indexOf("Opera") > -1;
if (isOpera) {
return "Opera"
};
if (userAgent.indexOf("Firefox") > -1) {
return "Firefox";
}
if (userAgent.indexOf("Chrome") > -1){
return "Chrome";
}
if (userAgent.indexOf("Safari") > -1) {
return "Safari";
}
if (userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera) {
return "IE";
};
if(userAgent.indexOf("Trident/7.0") > -1){
return 'IE Edge'
}
}