Home > Article > Web Front-end > js code to determine browser type IE, FF, Opera, Safari, chrome and version_javascript skills
Due to ie10-ie11 version issues, document.all judgment is no longer supported, so the ie judgment function needs to be rewritten
function isIE() { //ie? if (!!window.ActiveXObject || "ActiveXObject" in window) return true; else return false; }
The first type only distinguishes the browser, regardless of the version
//The following is to call the above function
var mb = myBrowser();
if ("IE" == mb) {
alert("I am IE");
}
if ("FF" == mb) {
alert("I am Firefox");
}
if ("Chrome" == mb) {
alert("I am Chrome");
}
if ("Opera" == mb) {
alert("I am Opera");
}
if ("Safari" == mb) {
alert("I am Safari");
}
Second, differentiate between browsers and consider IE5.5 6 7 8
The following is a JS code that determines whether the current browser is IE.
The principle is made by taking advantage of the difference in the toString method of processing arrays between IE and standard browsers. For standard browsers, if the last character in the array is a comma, the JS engine will automatically remove it.