Home  >  Article  >  Web Front-end  >  The shortest IE judgment code_javascript skills

The shortest IE judgment code_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:09:30968browse

Code:
var ie = ! "v1";
Only 7bytes required! See this article, "32 bytes, ehr ... 9, ehr ... 7!!! to know if your browser is IE", which tells how foreigners change the judgment of IE from 32 bytes The story of reducing it to 7 bytes step by step
But this record was broken by a Russian on January 8 this year, and now it is only 6 bytes! It takes advantage of the difference between IE and standard browsers in the toString method of processing arrays. It's done. For standard browsers, if the last character in the array is a comma, the JS engine will automatically remove it.
Code:

Copy code The code is as follows:

var ie = !-[1 ,];
var ie = !-[1,];
alert(ie);

If judged from a non-IE perspective, one bit can be saved because we are compatible At that time, in most cases, construction started in IE and non-IE places.
Code:
Copy code The code is as follows:

var notIE = -[1, ];
if(-[1,]){
alert("This is not IE!");
}else{
alert("This is IE!");
}
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