The code is as follows:
var isIE=!!window.ActiveXObject;
var isIE6=isIE&&!window.XMLHttpRequest;
var isIE8=isIE&&!!document.documentMode;
var isIE7=isIE&&!isIE6&&!isIE8;
if (isIE){
if (isIE6){
alert(”ie6″);
}
}
The above is a commonly used JavaScript code to detect which version of IE the browser is.
In January this year, a Russian took advantage of the difference between IE and standard browsers in the toString method of processing arrays, and perfectly used 6bytes:!-[1,] to complete the detection of whether it is an IE browser. . The previous shortest code was: ! 7bytes of "v1". Using these findings we can also make our code shorter and more artistic. Nowadays, detecting whether it is IE6 can actually be written as
!-[1,]&&!window.XMLHttpRequest
This code is quite useful in actual use. Since it can be written shorter, why not do it. Compared with the previous cumbersome analysis of the navigator and then the regular comparison method, it is certainly more efficient, and the code is more concise. In the process of writing JavaScript, you should make more use of operators such as ||, &&, !, !!, not just in cases like if().
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn