获取浏览器版本
<script>
function getBrowser() {
var UserAgent = navigator.userAgent.toLowerCase();
var browserInfo = {};
var browserArray = {
IE: window.ActiveXObject || "ActiveXObject" in window,
Chrome: UserAgent.indexOf('chrome') > -1 && UserAgent.indexOf('safari') > -1,
Firefox: UserAgent.indexOf('firefox') > -1,
Opera: UserAgent.indexOf('opera') > -1,
Safari: UserAgent.indexOf('safari') > -1 && UserAgent.indexOf('chrome') == -1,
Edge: UserAgent.indexOf('edge') > -1,
QQBrowser: /qqbrowser/.test(UserAgent),
WeixinBrowser: /MicroMessenger/i.test(UserAgent)
};
for (var i in browserArray) {
if (browserArray[i]) {
var versions = '';
if (i == 'IE') {
versions = UserAgent.match(/(msie\s|trident.*rv:)([\w.]+)/)[2];
} else if (i == 'Chrome') {
for (var mt in navigator.mimeTypes) {
if (navigator.mimeTypes[mt]['type'] == 'application/360softmgrplugin') {
i = '360';
}
}
versions = UserAgent.match(/chrome\/([\d.]+)/)[1];
} else if (i == 'Firefox') {
versions = UserAgent.match(/firefox\/([\d.]+)/)[1];
} else if (i == 'Opera') {
versions = UserAgent.match(/opera\/([\d.]+)/)[1];
} else if (i == 'Safari') {
versions = UserAgent.match(/version\/([\d.]+)/)[1];
} else if (i == 'Edge') {
versions = UserAgent.match(/edge\/([\d.]+)/)[1];
} else if (i == 'QQBrowser') {
versions = UserAgent.match(/qqbrowser\/([\d.]+)/)[1];
}
browserInfo.type = i; browserInfo.versions = parseInt(versions);
}
} return browserInfo;
}
</script>