Js judges IE6/IE7/FF code [XMLHttpRequest]

Source: Internet
Author: User

Sometimes, you may want to add some stuff to the page, which is limited to the differences in the browser, and the effects may not be shown. Now we can think of the browser's judgment and give different display effects based on different browsers, is it amazing? Of course, a lot of people can think of it. It's like the advertisement adding method of dachu network. It really shows me how to train a real JS master, read the Code:

Copy codeThe Code is as follows: if (window. XMLHttpRequest) {// Mozilla, Safari, IE7
Alert ('mozilla, Safari, ie7 ');
If (! Window. ActiveXObject) {// Mozilla, Safari,
Alert ('mozilla, Safari ');
} Else {
Alert ('ie7 ');
}
} Else {
Alert ('ie6 ');
}

Next, let's take a look at some JavaScript scripts written by some cool people on the Internet to judge IE and FF and IE6 IE7 IE8 of each IE version:
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:Copy codeThe Code is as follows: if (document. all ){
Alert ("IE browser ");
} Else {
Alert ("non-IE browser ");
}

Program codeCopy codeThe Code is as follows: if (!! Window. ActiveXObject ){
Alert ("IE browser ");
} Else {
Alert ("non-IE browser ");
}

The following describes how to differentiate IE6, IE7, and IE8:Copy codeThe Code is as follows: 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.

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.