JS is used to distinguish ie from other browsers and methods between IE6-8.
1. Document. All
2 ,!! Window. activexobject;
The usage is as follows:
If (document. All ){
Alert ("IE browser ");
} Else {
Alert ("non-IE browser ");
}
If (!! Window. activexobject ){
Alert ("IE browser ");
} Else {
Alert ("non-IE browser ");
}
The following describes how to differentiate IE6, IE7, and IE8:
VaR isie = !! Window. activexobject;
VaR isie6 = isie &&! Window. XMLHttpRequest;
VaR isie8 = isie &&!! Document.doc umentmode;
VaR isie7 = isie &&! Isie6 &&! Isie8;
If (isie ){
If (isie6 ){
Alert ("IE6 ″);
} Else if (isie8 ){
Alert ("IE8 ″);
} Else if (isie7 ){
Alert ("IE7 ″);
}
}
First, we make sure that this browser is IE and has been tested once. If you have doubts about this, you can test it.
I am using it directly here. You can declare them as variables for use. It is said that Firefox will also add the document. All method in the future. Therefore, it is recommended to use the second method, which should be safer.
Use navigator. useragent. indexof () to differentiate multiple browsers. The code example is as follows:
<HTML>
<Head>
<Title> tag index Web </title>
</Head>
<Body>
<SCRIPT type = "text/JavaScript">
Document. Write ('browser judgment :');
// Contains the "Opera" text Column
If (navigator. useragent. indexof ("Opera ")! =-1 ){
Document. Write ('is opera used in your browser? ');
}
// Contains the "MSIE" text Column
Else if (navigator. useragent. indexof ("MSIE ")! =-1 ){
Document. Write ('Internet explorer in your browser? ');
}
// Contains the "Firefox" text Column
Else if (navigator. useragent. indexof ("Firefox ")! =-1 ){
Document. Write ('Firefox in your browser? ');
}
// Contains the "Netscape" text Column
Else if (navigator. useragent. indexof ("Netscape ")! =-1 ){
Document. Write ('netscape in your browser? ');
}
// Contains the safari text Column
Else if (navigator. useragent. indexof ("safari ")! =-1 ){
Document. Write ('safari in your browser? ');
}
Else {
Document. Write ('unrecognized browser. ');
}
Document. Write ('');
</SCRIPT>
</Body>
</Html>