Front-end JS Judgment Browser
Now there are many browsers on the market, such as 360, QQ, Sogou and so on. But most of them are based on several existing browser kernels for secondary development. How many kernels are there in the end?
1. Trident Kernel (IE Kernel)
2. Gecko Kernel (FireFox Kernel)
3. Presto Kernel (Opera Kernel (Abandoned)/* The Google Kernel now used by Opera*/
4. Webkit (Safari Kernel, Chrome Kernel Prototype, Open Source)
5. Blink (browser typesetting engine developed by Google and Opera Software)
There are many browsers on the market, but the browser kernel is just these kinds. We can use Js code to get the browser's core when users visit our web pages.
1. Judging whether it is an IE browser or not, return to the version of IE browser
var userAgent = navigator.userAgent //Get the browser's userAgent string var isIE = userAgent.indexOf('compatible') > -1 && userAgent.indexOf('MSIE') > -1 //Determine whether IE<11 browser is available var isEdge = userAgent.indexOf('Edge') > -1 && !isIE //Edge Browser for IE var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf('rv:11.0') > -1 if (isIE) { var reIE = new RegExp('MSIE (\\d+\\.\\d+);') reIE.test(userAgent) var fIEVersion = parseFloat(RegExp['$1']) if (fIEVersion == 7) { return 7 } else if (fIEVersion == 8) { return 8 } else if (fIEVersion == 9) { return 9 } else if (fIEVersion == 10) { return 10 } else { return 6 //IE Version <=7 } } else if (isEdge) { return 'edge' //edge } else if (isIE11) { return 11 //IE11 } else { return -1 //Not ie browser }
2. Judging whether it is a few other browsers
var userAgent = navigator.userAgent; //Get the browser's userAgent string var isOpera = userAgent.indexOf("Opera") > -1; if (isOpera) { //Judging Opera Browser return "Opera" } if (userAgent.indexOf("Firefox") > -1) { //Determine whether Firefox browsers are available return "FF"; } if (userAgent.indexOf("Chrome") > -1) { //Determine whether it's Google Browser or not return "Chrome"; } if (userAgent.indexOf("Safari") > -1) { //Determine whether Safari browser is available or not return "Safari"; } if (userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera) { //Judging whether IE browser or not return "IE"; }