This article introduces how to judge the browser type by js. If you need it, refer to the code below:
The 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 ″);
}
}
The above is a common JavaScript code used to detect which version of the browser is IE.
In January 1 this year, the Russians used the difference between IE and the standard browser in handling the toString method of arrays, making perfect use of 6 bytes :! -[1,] checks whether the browser is an IE browser. The shortest code is :! + 7 bytes of "v1. Using these findings, we can also make our code shorter and more artistic. Check whether IE6 can be written
! -[1,] &! Window. XMLHttpRequest
This code is useful in actual use. Since it can be written in a shorter time, why not. Compared with the previously cumbersome analysis navigator, the regular expression comparison method is of course more efficient, and the code is more concise. In the JavaScript writing process, we should make full use of such features as || ,&&,! ,!! Such operators are not only in the case of if.