A wonderful Internet Explorer in JavaScript the method of judging _javascript skills

Source: Internet
Author: User
One way to remember that many of the sources that are used most on the Internet is:
Copy Code code as follows:
var ie = document.all ();

This is because IE browser's document has all method, and the so-called standard browser is not, so for a long time, this is a very common method.
After that, everyone started to pursue brevity, as one of the popular methods after this:
Copy Code code as follows:
var ie =! + "\V1";

This is the use of IE does not support the characteristics of vertical tabs, only 7 characters have been very shocking, but this record was a Russian earlier this year broke, people only need 6 characters can be done.
We will not discuss what this character can do for the moment, but think of it as a study, or whatever pain you say he is idle (spit ~).
Copy Code code as follows:
var ie =! -[1,];

In fact its principle is very simple, [1,] in the standard browser will return the string "1", equivalent to the call [1,].tostring,ie return "1,". However, ie and standards will be detected, so use the minus cast to the number, the standard can successfully converted to 1, 1 will be automatically converted to true in if, and IE is converted to Nan, and then automatically converted to false! View Demo.
It's simple, right? There must be a lot of people like me thinking, how could I not have thought of it? Yes, why didn't I think of it? (Laughter ~)
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.