The example in this article describes how js determines the browser version and browser kernel. Share it with everyone for your reference. The specific implementation method is as follows:
webkit: (agent.indexOf(' applewebkit/') > -1),
mac: (agent.indexOf('macintosh') > -1),
quirks: (document.compatMode == 'BackCompat')
};
//Detect whether the current browser kernel is gecko kernel
browser.gecko = (navigator.product == 'Gecko' && !browser.webkit && !browser.opera && !browser.ie);
// Internet Explorer 6.0
var v1 = agent.match(/(?:msies([w.] ))/);
var v2 = agent.match(/(?:trident.*rv:([w.] ))/);
If (v1 && v2 && v1[1] && v2[1]) {
Version = Math.max(v1[1] * 1, v2[1] * 1);
} else if (v1 && v1[1]) {
Version = v1[1] * 1;
} else if (v2 && v2[1]) {
Version = v2[1] * 1;
} else {
version = 0;
}
//Detect whether the browser mode is IE11 compatibility mode
browser.ie11Compat = document.documentMode == 11;
//Detect whether the browser mode is IE9 compatibility mode
browser.ie9Compat = document.documentMode == 9;
//Detect whether the browser mode is IE10 compatible mode
browser.ie10Compat = document.documentMode == 10;
//Detect whether the browser is IE8 browser
browser.ie8 = !!document.documentMode;
//Detect whether the browser mode is IE8 compatible mode
browser.ie8Compat = document.documentMode == 8;
//Detect whether the browser mode is IE7 compatibility mode
browser.ie7Compat = ((version == 7 && !document.documentMode) || document.documentMode == 7);
//Detect whether the browser mode is IE6 mode or weird mode
browser.ie6Compat = (version < 7 || browser.quirks);
browser.ie9above = version > 8;
browser.ie9below = version < 9;
}
// Gecko.
If (browser.gecko) {
var geckoRelease = agent.match(/rv:([d.] )/);
If (geckoRelease) {
geckoRelease = geckoRelease[1].split('.');
version = geckoRelease[0] * 10000 (geckoRelease[1] || 0) * 100 (geckoRelease[2] || 0) * 1;
}
If (/chrome/(d .d)/i.test(agent)) {
browser.chrome = RegExp['x241'];
}
If (/(d .d)?(?:.d)?s safari/?(d .d )?/i.test(agent) && !/chrome/i.test(agent)) {
browser.safari = (RegExp['x241'] || RegExp['x242']);
}
If (browser.opera)
Version = parseFloat(opera.version());
If (browser.webkit)
Version = parseFloat(agent.match(/ applewebkit/(d )/)[1]);
browser.version = version;
}();