判断浏览器内核
// 判断浏览器内核 browserKernel() { var u = navigator.userAgent, app = navigator.appVersion return { trident: u.indexOf('Trident') > -1, //IE内核 presto: u.indexOf('Presto') > -1, //opera内核 webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核 gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核 mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端 ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端 android: u.indexOf('Android') > -1 || u.indexOf('Adr') > -1, //android终端 iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器 iPad: u.indexOf('iPad') > -1, //是否iPad webApp: u.indexOf('Safari') == -1, //是否web应该程序,没有头部与底部 weixin: u.indexOf('MicroMessenger') > -1, //是否微信 (2015-01-22新增) qq: u.match(/\sQQ/i) == ' qq' //是否QQ } }判断浏览器
// 判断浏览器 browser() { //取得浏览器的userAgent字符串 var userAgent = navigator.userAgent //判断是否Opera浏览器 var isOpera = userAgent.indexOf('Opera') > -1 //判断是否IE浏览器 var isIE = userAgent.indexOf('compatible') > -1 && userAgent.indexOf('MSIE') > -1 && !isOpera //判断是否IE的Edge浏览器 var isEdge = userAgent.indexOf('Edge') > -1 //判断是否Firefox浏览器 var isFF = userAgent.indexOf('Firefox') > -1 //判断是否Safari浏览器 var isSafari = userAgent.indexOf('Safari') > -1 && userAgent.indexOf('Chrome') == -1 //判断Chrome浏览器 var isChrome = userAgent.indexOf('Chrome') > -1 && userAgent.indexOf('Safari') > -1 if (isIE) { var reIE = new RegExp('MSIE (\\d+\\.\\d+);') reIE.test(userAgent) var fIEVersion = parseFloat(RegExp['$1']) if (fIEVersion == 7) { return 'IE7' } else if (fIEVersion == 8) { return 'IE8' } else if (fIEVersion == 9) { return 'IE9' } else if (fIEVersion == 10) { return 'IE10' } else if (fIEVersion == 11) { return 'IE11' } else { return '0' } //IE版本过低 return 'IE' } if (isOpera) { return 'Opera' } if (isEdge) { return 'Edge' } if (isFF) { return 'FF' } if (isSafari) { return 'Safari' } if (isChrome) { return 'Chrome' } }
判断客户端
IsApp() { var userAgentInfo = navigator.userAgent var Agents = [ 'Android', 'iPhone', 'SymbianOS', 'Windows Phone', 'iPad', 'iPod' ] var flag = false for (var v = 0; v < Agents.length; v++) { if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = true break } } console.log(flag) return flag }