JS is used to distinguish between IE and other browsers and Ie6-8 methods.
1, document.all
2 、!! Window. ActiveXObject;
Here's 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");
}
Here's how to differentiate between IE6, IE7, and IE8:
varisie=!!window. ActiveXObject;varisie6=isie&&!window. XMLHttpRequest;varisie8=isie&&!!Document.documentmode;varisie7=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 for IE's case, carried out at once the detection, if you have doubts about this, you can test it.
I use it directly in my judgments, and you can use them to declare them as variables first. It is said that Firefox will also join document.all this way, so it is recommended to use the second method, it should be more secure.
Using Navigator.userAgent.indexOf () to differentiate multiple browsers, the code examples are as follows:
<HTML> <Head> <title>TAG Index Web</title> </Head> <Body> <Scripttype= "Text/javascript">document.write ('Browser Award:'); //contains "opera" text columns if(Navigator.userAgent.indexOf ("Opera") != -1) {document.write ('your browser when opera bar? '); } //contains "msie" text columns Else if(Navigator.userAgent.indexOf ("MSIE") != -1) {document.write ('is Internet Explorer in your browser? '); } //contains "firefox" text columns Else if(Navigator.userAgent.indexOf ("Firefox") != -1) {document.write ('your browser when Firefox bar? '); } //contains "netscape" text columns Else if(Navigator.userAgent.indexOf ("Netscape") != -1) {document.write ('is your browser Netscape? '); } //contains "safari" text columns Else if(Navigator.userAgent.indexOf ("Safari") != -1) {document.write ('your browser when Safari bar? '); }Else{document.write ('Unrecognized browser. '); } document.write ("'); </Script> </Body></HTML>
Transferred from: http://hi.baidu.com/sqq_qqs/item/b0c508c2e960193c0831c676
JavaScript determines browser type