function c_getBrowserName() {
var ua = navigator.userAgent.toLowerCase();
/* ie11 edge需要提前判断*/
var Sys = {},s;
(s = ua.match(/edge\/([\d.]+)/)) ? Sys.edge = s[1] :
(s = ua.match(/rv:([\d.]+)\) like gecko/)) ? Sys.ie = s[1] : 0;
if (Sys.edge) return { broswer : "Edge", version : Sys.edge };
if (Sys.ie&&Sys.ie==11) return { broswer : "IE", version : Sys.ie };
/* ie11 edge需要提前判断 end*/
var engine = { ie: 0, webkit: 0, gecko: 0, opera: 0, khtml: 0 },
browser = { se360: 0,ubrowser:0, se: 0, maxthon: 0, qq: 0, tt: 0, theworld: 0, cometbrowser: 0, greenbrowser: 0, ie: 0, chrome: 0, netscape: 0, firefox: 0, opera: 0, safari: 0, konq: 0 };
for (var type in engine) {
if (typeof type === 'string') {
var regexp = 'gecko' === type ? /rv:([\w.]+)/ : RegExp(type + '[ \\/]([\\w.]+)');
if (regexp.test(ua)) {
engine.version = window.opera ? window.opera.version() : RegExp.$1;
engine[type] = parseFloat(engine.version);
engine.type = type;
break;
}
}
}
for (var type in browser) {
if (typeof type === 'string') {
var regexp = null;
switch(type) {
case "se360": regexp = /360se(?:[ \/]([\w.]+))?/; break;
case "se": regexp = /se ([\w.]+)/; break;
case "qq": regexp = /qqbrowser\/([\w.]+)/; break;
case "tt": regexp = /tencenttraveler ([\w.]+)/; break;
case "ubrowser": regexp = /ubrowser\/([\w.]+)/; break;
case "safari": regexp = /version\/([\w.]+)/; break;
case "konq": regexp = /konqueror\/([\w.]+)/; break;
case "netscape": regexp = /navigator\/([\w.]+)/; break;
default: regexp = RegExp(type + '(?:[ \\/]([\\w.]+))?');
}
if (regexp.test(ua)) {
browser.version = window.opera ? window.opera.version() : RegExp.$1 ? RegExp.$1 : 'unknown';
browser[type] = parseFloat(browser.version);
browser.type = type;
break;
}
}
}
var browserName = {
se360: '360安全浏览器',
se: '搜狗高速浏览器',
maxthon: '遨游',
qq: 'QQ浏览器',
tt: '腾讯TT',
theworld: '世界之窗',
cometbrowser: '彗星浏览器',
greenbrowser: 'GreenBrowser',
ie: 'IE',
chrome: '谷歌Chrome',
netscape: '网景',
firefox: '火狐',
opera: 'Opera',
safari: '苹果Safari',
konq: 'Konqueror',
ubrowser:'UC浏览器',
et:'wps_et',
wpp:'wps_wpp',
wps:'wps_wps',
};
if(!browserName[browser.type]){
browser={et:0,wps:0,wpp:0};
for (var type in browser) {
if (typeof type === 'string') {
var regexp = null;
switch(type) {
case "et": regexp = /et\/([\w.]+)/; break;
case "wps": regexp = /wps\/([\w.]+)/; break;
case "wpp": regexp = /wpp\/([\w.]+)/; break;
}
if (regexp.test(ua)) {
browser.version = window.opera ? window.opera.version() : RegExp.$1 ? RegExp.$1 : 'unknown';
browser[type] = parseFloat(browser.version);
browser.type = type;
break;
}
}
}
}
return { broswer : browserName[browser.type]?(browser.type=='IE'?browserName[browser.type]+browser.version:browserName[browser.type]):'other', version : browser.version };
};
//获取浏览器名称
function collect_getBrowserName(){
var Sys = {};
var ua = navigator.userAgent.toLowerCase();
var s;
(s = ua.match(/edge\/([\d.]+)/)) ? Sys.edge = s[1] :
(s = ua.match(/rv:([\d.]+)\) like gecko/)) ? Sys.ie = s[1] :
(s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] :
(s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] :
(s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] :
(s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] :
(s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;
if (Sys.edge) return { broswer : "Edge", version : Sys.edge };
if (Sys.ie) return { broswer : "IE", version : Sys.ie };
if (Sys.firefox) return { broswer : "Firefox", version : Sys.firefox };
if (Sys.chrome) return { broswer : "Chrome", version : Sys.chrome };
if (Sys.opera) return { broswer : "Opera", version : Sys.opera };
if (Sys.safari) return { broswer : "Safari", version : Sys.safari };
return { broswer : "", version : "0" };
}
第二种更全 不能识别edge和ie11
function collect_getBrowserName2() {
var engine = { ie: 0, webkit: 0, gecko: 0, opera: 0, khtml: 0 },
browser = { se360: 0,ubrowser:0, se: 0, maxthon: 0, qq: 0, tt: 0, theworld: 0, cometbrowser: 0, greenbrowser: 0, ie: 0, chrome: 0, netscape: 0, firefox: 0, opera: 0, safari: 0, konq: 0 },
ua = navigator.userAgent.toLowerCase();
for (var type in engine) {
if (typeof type === 'string') {
var regexp = 'gecko' === type ? /rv:([\w.]+)/ : RegExp(type + '[ \\/]([\\w.]+)');
if (regexp.test(ua)) {
engine.version = window.opera ? window.opera.version() : RegExp.$1;
engine[type] = parseFloat(engine.version);
engine.type = type;
break;
}
}
}
for (var type in browser) {
if (typeof type === 'string') {
var regexp = null;
switch(type) {
case "se360": regexp = /360se(?:[ \/]([\w.]+))?/; break;
case "se": regexp = /se ([\w.]+)/; break;
case "qq": regexp = /qqbrowser\/([\w.]+)/; break;
case "tt": regexp = /tencenttraveler ([\w.]+)/; break;
case "ubrowser": regexp = /ubrowser\/([\w.]+)/; break;
case "safari": regexp = /version\/([\w.]+)/; break;
case "konq": regexp = /konqueror\/([\w.]+)/; break;
case "netscape": regexp = /navigator\/([\w.]+)/; break;
default: regexp = RegExp(type + '(?:[ \\/]([\\w.]+))?');
}
if (regexp.test(ua)) {
browser.version = window.opera ? window.opera.version() : RegExp.$1 ? RegExp.$1 : 'unknown';
browser[type] = parseFloat(browser.version);
browser.type = type;
break;
}
}
}
var browserName = {
se360: '360安全浏览器',
se: '搜狗高速浏览器',
maxthon: '遨游',
qq: 'QQ浏览器',
tt: '腾讯TT',
theworld: '世界之窗',
cometbrowser: '彗星浏览器',
greenbrowser: 'GreenBrowser',
ie: '微软IE',
chrome: '谷歌Chrome',
netscape: '网景',
firefox: '火狐',
opera: 'Opera',
safari: '苹果Safari',
konq: 'Konqueror',
ubrowser:'UC浏览器'
};
return { broswer : browserName[browser.type], version : browser.version };
};