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

Concise and short JavaScript IE browser judgment code_javascript skills

WBOY
Release: 2016-05-16 18:31:39
Original
955 people have browsed it

The world's shortest Javascript method to determine IE browser comes from Russia! It has been tested on various versions of IE and other currently popular browsers. Although Microsoft has been aware of IE-based bugs, it has never corrected them.

Copy code The code is as follows:



The above code running result: return true under IE, other standards The browser returns false. !-[1,], only 6 bytes!
But if you judge the other way around, if the standard browser returns true and IE returns false, you can shorten it by one byte.
Copy code The code is as follows:



After reading this, are you curious about how these work? Please continue reading below.
The reason for this bug is that IE will add an empty array element to the total number of array elements.
[1,]. Length standard browser will return 1 (based on standard ECMAscript, the comma "," at the end of the array will be ignored, this is to facilitate display in a column and automatic generation, etc.), but IE will Return 2. When you print this array IE will return "1, ", which is two elements, while other standard browsers will return "1".
This is easy to verify, such as running the following code in IE and FF:
Copy the code The code is as follows:

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!