标签:
function _browser() { var ieAX = window.ActiveXObject; var ieMode = document.documentMode; var ieVer = _getIeVersion() || ieMode || 0; var isIe = ieAX || ieMode; var chromiumType = _getChromiumType(); return { isIE: (function () { return !!ieVer; })(), ieVersion: (function () { return ieVer; })(), isChrome: (function () { return chromiumType === ‘chrome‘; })(), is360se: (function () { return chromiumType === ‘360se‘; })(), is360ee: (function () { return chromiumType === ‘360ee‘; })(), isLiebao: (function () { return chromiumType === ‘liebao‘; })(), isSogou: (function () { return chromiumType === ‘sogou‘; })(), isQQ: (function () { return chromiumType === ‘qq‘; })() }; /** * 检测 external 是否包含该字段 * @param reg 正则 * @param type 检测类型,0为键,1为值 * @returns {boolean} * @private */ function _testExternal(reg, type) { var external = window.external || {}; for (var i in external) { if (reg.test(type ? external[i] : i)) { return true; } } return false; } /** * 获取 Chromium 内核浏览器类型 * @link http://www.adtchrome.com/js/help.js * @link https://ext.chrome.360.cn/webstore * @link https://ext.se.360.cn * @return {String} * 360ee 360极速浏览器 * 360se 360安全浏览器 * sougou 搜狗浏览器 * liebao 猎豹浏览器 * chrome 谷歌浏览器 * ‘‘ 无法判断 * @version 1.0 * 2014年3月12日20:39:55 */ function _getChromiumType() { if (isIe || typeof window.scrollMaxX !== ‘undefined‘) { return ‘‘; } var _track = ‘track‘ in document.createElement(‘track‘); var webstoreKeysLength = window.chrome && window.chrome.webstore ? Object.keys(window.chrome.webstore).length : 0; // 搜狗浏览器 if (_testExternal(/^sogou/i, 0)) { return ‘sogou‘; } // 猎豹浏览器 if (_testExternal(/^liebao/i, 0)) { return ‘liebao‘; } // chrome if (window.clientInformation && window.clientInformation.languages && window.clientInformation.languages.length > 2) { return ‘chrome‘; } if (_track) { // 360极速浏览器 // 360安全浏览器 return webstoreKeysLength > 1 ? ‘360ee‘ : ‘360se‘; } return ‘‘; } // 获得ie浏览器版本 function _getIeVersion() { var v = 3, p = document.createElement(‘p‘), all = p.getElementsByTagName(‘i‘); while ( p.innerHTML = ‘<!--[if gt IE ‘ + (++v) + ‘]><i></i><![endif]-->‘, all[0]); return v > 4 ? v : 0; } }
标签:
原文地址:http://www.cnblogs.com/everyone/p/4530256.html