/** * 浏览器解析,浏览器、node.js皆可 * https://github.com/mumuy/browser */ (function (root, factory) { if (typeof define === 'function' && define.amd) { // amd define(factory) } else if (typeof exports === 'object') { // node, commonjs-like module.exports = factory() } else { // browser globals (root is window) root.browser = factory() } }(this, function () { var _window = window||{}; var _navigator = navigator||{}; return function (useragent) { var u = useragent || _navigator.useragent; var _this = this; var match = { //内核 'trident': u.indexof('trident') > -1 || u.indexof('net clr') > -1, 'presto': u.indexof('presto') > -1, 'webkit': u.indexof('applewebkit') > -1, 'gecko': u.indexof('gecko/') > -1, //浏览器 'safari': u.indexof('safari') > -1, 'chrome': u.indexof('chrome') > -1 || u.indexof('crios') > -1, 'ie': u.indexof('msie') > -1 || u.indexof('trident') > -1, 'edge': u.indexof('edge') > -1, 'firefox': u.indexof('firefox') > -1 || u.indexof('fxios') > -1, 'firefox focus': u.indexof('focus') > -1, 'chromium': u.indexof('chromium') > -1, 'opera': u.indexof('opera') > -1 || u.indexof('opr') > -1, 'vivaldi': u.indexof('vivaldi') > -1, 'yandex': u.indexof('yabrowser') > -1, 'kindle': u.indexof('kindle') > -1 || u.indexof('silk/') > -1, '360': u.indexof('360ee') > -1 || u.indexof('360se') > -1, 'uc': u.indexof('uc') > -1 || u.indexof(' ubrowser') > -1, 'qqbrowser': u.indexof('qqbrowser') > -1, 'qq': u.indexof('qq/') > -1, 'baidu': u.indexof('baidu') > -1 || u.indexof('bidubrowser') > -1, 'maxthon': u.indexof('maxthon') > -1, 'sogou': u.indexof('metasr') > -1 || u.indexof('sogou') > -1, 'lbbrowser': u.indexof('lbbrowser') > -1, '2345explorer': u.indexof('2345explorer') > -1, 'theworld': u.indexof('theworld') > -1, 'xiaomi': u.indexof('miuibrowser') > -1, 'quark': u.indexof('quark') > -1, 'qiyu': u.indexof('qiyu') > -1, 'wechat': u.indexof('micromessenger') > -1, 'taobao': u.indexof('aliapp(tb') > -1, 'alipay': u.indexof('aliapp(ap') > -1, 'weibo': u.indexof('weibo') > -1, 'douban': u.indexof('com.douban.frodo') > -1, 'suning': u.indexof('snebuy-app') > -1, 'iqiyi': u.indexof('iqiyiapp') > -1, //系统或平台 'windows': u.indexof('windows') > -1, 'linux': u.indexof('linux') > -1 || u.indexof('x11') > -1, 'mac os': u.indexof('macintosh') > -1, 'android': u.indexof('android') > -1 || u.indexof('adr') > -1, 'ubuntu': u.indexof('ubuntu') > -1, 'freebsd': u.indexof('freebsd') > -1, 'debian': u.indexof('debian') > -1, 'windows phone': u.indexof('iemobile') > -1, 'blackberry': u.indexof('blackberry') > -1 || u.indexof('rim') > -1, 'meego': u.indexof('meego') > -1, 'symbian': u.indexof('symbian') > -1, 'ios': u.indexof('like mac os x') > -1, 'chrome os': u.indexof('cros') > -1, 'webos': u.indexof('hpwos') > -1, //设备 'mobile': u.indexof('mobi') > -1 || u.indexof('iph') > -1 || u.indexof('480') > -1, 'tablet': u.indexof('tablet') > -1 || u.indexof('pad') > -1 || u.indexof('nexus 7') > -1 }; //修正 if (match['mobile']) { match['mobile'] = !(u.indexof('ipad') > -1); } else if (_window.showmodaldialog && _window.chrome) { match['360'] = true; } //基本信息 var hash = { engine: ['webkit', 'trident', 'gecko', 'presto'], browser: ['safari', 'chrome', 'edge', 'ie', 'firefox', 'firefox focus', 'chromium', 'opera', 'vivaldi', 'yandex', 'kindle', '360', 'uc', 'qqbrowser', 'qq', 'baidu', 'maxthon', 'sogou', 'lbbrowser', '2345explorer', 'theworld', 'xiaomi', 'quark', 'qiyu', 'wechat', 'taobao', 'alipay', 'weibo', 'douban','suning', 'iqiyi'], os: ['windows', 'linux', 'mac os', 'android', 'ubuntu', 'freebsd', 'debian', 'ios', 'windows phone', 'blackberry', 'meego', 'symbian', 'chrome os', 'webos'], device: ['mobile', 'tablet'] }; _this.device = 'pc'; _this.language = (function () { var g = (_navigator.browserlanguage || _navigator.language); var arr = g.split('-'); if (arr[1]) { arr[1] = arr[1].touppercase(); } return arr.join('_'); })(); for (var s in hash) { for (var i = 0; i < hash[s].length; i++) { var value = hash[s][i]; if (match[value]) { _this[s] = value; } } } //系统版本信息 var osversion = { 'windows': function () { var v = u.replace(/^.*windows nt ([\d.]+);.*$/, '$1'); var hash = { '6.4': '10', '6.3': '8.1', '6.2': '8', '6.1': '7', '6.0': 'vista', '5.2': 'xp', '5.1': 'xp', '5.0': '2000' }; return hash[v] || v; }, 'android': function () { return u.replace(/^.*android ([\d.]+);.*$/, '$1'); }, 'ios': function () { return u.replace(/^.*os ([\d_]+) like.*$/, '$1').replace(/_/g, '.'); }, 'debian': function () { return u.replace(/^.*debian\/([\d.]+).*$/, '$1'); }, 'windows phone': function () { return u.replace(/^.*windows phone( os)? ([\d.]+);.*$/, '$2'); }, 'mac os': function () { return u.replace(/^.*mac os x ([\d_]+).*$/, '$1').replace(/_/g, '.'); }, 'webos': function () { return u.replace(/^.*hpwos\/([\d.]+);.*$/, '$1'); } } _this.osversion = ''; if (osversion[_this.os]) { _this.osversion = osversion[_this.os](); if (_this.osversion == u) { _this.osversion = ''; } } //浏览器版本信息 var version = { 'safari': function () { return u.replace(/^.*version\/([\d.]+).*$/, '$1'); }, 'chrome': function () { return u.replace(/^.*chrome\/([\d.]+).*$/, '$1').replace(/^.*crios\/([\d.]+).*$/, '$1'); }, 'ie': function () { return u.replace(/^.*msie ([\d.]+).*$/, '$1').replace(/^.*rv:([\d.]+).*$/, '$1'); }, 'edge': function () { return u.replace(/^.*edge\/([\d.]+).*$/, '$1'); }, 'firefox': function () { return u.replace(/^.*firefox\/([\d.]+).*$/, '$1').replace(/^.*fxios\/([\d.]+).*$/, '$1'); }, 'firefox focus': function () { return u.replace(/^.*focus\/([\d.]+).*$/, '$1'); }, 'chromium': function () { return u.replace(/^.*chromium\/([\d.]+).*$/, '$1'); }, 'opera': function () { return u.replace(/^.*opera\/([\d.]+).*$/, '$1').replace(/^.*opr\/([\d.]+).*$/, '$1'); }, 'vivaldi': function () { return u.replace(/^.*vivaldi\/([\d.]+).*$/, '$1'); }, 'yandex': function () { return u.replace(/^.*yabrowser\/([\d.]+).*$/, '$1'); }, 'kindle': function () { return u.replace(/^.*version\/([\d.]+).*$/, '$1'); }, 'maxthon': function () { return u.replace(/^.*maxthon\/([\d.]+).*$/, '$1'); }, 'qqbrowser': function () { return u.replace(/^.*qqbrowser\/([\d.]+).*$/, '$1'); }, 'qq': function () { return u.replace(/^.*qq\/([\d.]+).*$/, '$1'); }, 'baidu': function () { return u.replace(/^.*bidubrowser[\s\/]([\d.]+).*$/, '$1'); }, 'uc': function () { return u.replace(/^.*uc?browser\/([\d.]+).*$/, '$1'); }, 'sogou': function () { return u.replace(/^.*se ([\d.x]+).*$/, '$1').replace(/^.*sogoumobilebrowser\/([\d.]+).*$/, '$1'); }, '2345explorer': function () { return u.replace(/^.*2345explorer\/([\d.]+).*$/, '$1'); }, 'theworld': function () { return u.replace(/^.*theworld ([\d.]+).*$/, '$1'); }, 'xiaomi': function () { return u.replace(/^.*miuibrowser\/([\d.]+).*$/, '$1'); }, 'quark': function () { return u.replace(/^.*quark\/([\d.]+).*$/, '$1'); }, 'qiyu': function () { return u.replace(/^.*qiyu\/([\d.]+).*$/, '$1'); }, 'wechat': function () { return u.replace(/^.*micromessenger\/([\d.]+).*$/, '$1'); }, 'taobao': function () { return u.replace(/^.*aliapp\(tb\/([\d.]+).*$/, '$1'); }, 'alipay': function () { return u.replace(/^.*aliapp\(ap\/([\d.]+).*$/, '$1'); }, 'weibo': function () { return u.replace(/^.*weibo__([\d.]+).*$/, '$1'); }, 'douban': function () { return u.replace(/^.*com.douban.frodo\/([\d.]+).*$/, '$1'); }, 'suning': function () { return u.replace(/^.*snebuy-app([\d.]+).*$/, '$1'); }, 'iqiyi': function () { return u.replace(/^.*iqiyiversion\/([\d.]+).*$/, '$1'); } }; _this.version = ''; if (version[_this.browser]) { _this.version = version[_this.browser](); if (_this.version == u) { _this.version = ''; } } //修正 if (_this.browser == 'edge') { _this.engine = 'edgehtml'; } else if (_this.browser == 'chrome' && parseint(_this.version) > 27) { _this.engine = 'blink'; } else if (_this.browser == 'opera' && parseint(_this.version) > 12) { _this.engine = 'blink'; } else if (_this.browser == 'yandex') { _this.engine = 'blink'; } }; })); var info = new browser(); if (info.browser == "ie" ) { if (info.version < 9) { alert("建议使用高版本浏览器浏览本页面!") } else {} } else {}