Home > Web Front-end > JS Tutorial > body text

A strange way to determine IE browser in JavaScript_javascript skills

WBOY
Release: 2016-05-16 16:52:16
Original
1416 people have browsed it

I remember that the most commonly used method for Downing many source codes on the Internet is:

Copy the code The code is as follows:
var ie = document.all();

This is because the IE browser has the all method under document, but the so-called standard browser does not, so for a long time, this is a very Universal method.
After that, everyone began to pursue brevity, just like a method that became popular after that:
Copy code Code As follows:
var ie = ! "v1";

This is determined by taking advantage of the fact that IE does not support vertical tab characters. It is shocking to only have 7 characters, but This record was broken by a Russian earlier this year, who only needed 6 characters to complete it.
We will not discuss what this character can do for the time being, but think of it as a kind of research, or if you say it is idle, then it will be okay (complaint~).
Copy code The code is as follows:
var ie = ! - [1,];

In fact, its principle is very simple. [1,] will return the string "1" in a standard browser, which is equivalent to calling [1,].toString, while IE will return "1,". But in this way, both IE and the standard will pass the detection, so using a negative sign to force conversion to a number, the standard can be successfully converted to 1, and 1 will be automatically converted to true in the if, while IE will be converted to NaN, and then automatically converted to false! View DEMO.
Simple, right? There must be many people thinking like me, why didn’t I think of this? Yeah, why didn’t I think of that? (laugh~)
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!