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.