JS 获取浏览器的名称和版本信息
var a=getBrowser();
console.log(a);
function getBrowser(){
var browser = {
msie: false,
firefox: false,
opera: false,
safari: false,
chrome: false,
netscape: false,
appname: 'unknown',
version: 0
},
ua = window.navigator.userAgent.toLowerCase();
if (/(msie|firefox|opera|chrome|netscape)\D+(\d[\d.]*)/.test(ua)) {
browser[RegExp.$1] = true;
browser.appname = RegExp.$1;
browser.version = RegExp.$2;
} else if (/version\D+(\d[\d.]*).*safari/.test(ua)) {
// safari
browser.safari = true;
browser.appname = 'safari';
browser.version = RegExp.$2;
}
return browser.appname + ' ' + browser.version;
}