JS distinguishes IE6, IE7, and IE8 Methods

Source: Internet
Author: User
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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.