js determines what type of browser it is
{
}
else if ( document.all && "object" == typeof( window.external ) ) // ie
{
}
1. document.all
2. !!window.ActiveXObject;
How to use it:
if (document.all){
alert("IE browser");
}else{
alert("non-IE browser");
}
if (!!window.ActiveXObject){
alert("IE browser");
}else{
alert("non-IE browser");
}
The following is how to distinguish between IE6, IE7 and IE8:
var isIE=!!window.ActiveXObject;
var isIE6=isIE&&!window.XMLHttpRequest;
var isIE8=isIE&&!!document.documentMode;
var isIE7=isIE&&!isIE6&&!isIE8;
if (isIE){
if (isIE6){
alert(”ie6″);
}else if (isIE8){
alert(”ie8″);
}else if (isIE7){
alert(”ie7″);
}
}
First of all, we make sure that this browser is tested once when it is IE. If you have doubts about this, you can test it.
I will use them directly in judgment here. You can also declare them as variables first for use. It is said that Firefox will also add the document.all method in the future, so it is recommended to use the second method, which should be safer.
Use navigator.userAgent.indexOf() to distinguish multiple browsers. The code example is as follows: