JavaScript: an amazing Method for judging ie browsers-javascript tips-js tutorial

Source: Internet
Author: User
When writing native Javascript, there are always some differences between the JS engine of IE and the JS engine of standard browsers, therefore, it is often used to determine whether the web browser is an Internet Explorer. Remember that the following is the most commonly used method for many source codes that are Down on the Internet:

The Code is as follows:

Var ie = document. all ();


This is because the document of IE browser has the all method, but the so-called standard browser does not, so this is a very common method for a long time.
After that, everyone began to pursue brief content, just like a method that was once popular after that:

The Code is as follows:

Var ie =! + "\ V1 ";


This is determined by the use of IE that does not support the characteristics of vertical tabs. Only seven characters are already shocking, but this record was broken by a Russian earlier this year, it takes only 6 characters to complete.
We will not discuss what this character can do for the moment, but think of it as a research, or you can say that it is idle ~).

The Code is as follows:

Var ie =! -[1,];


In fact, its principle is very simple, [1,] in the standard browser will return the string "1", equivalent to calling [1,]. toString, IE will return "1 ,". However, in this way, both IE and standard pass detection. Therefore, the negative sign is forcibly converted to a number. if the standard is successfully converted to, it is automatically converted to true in if, while IE is converted to NaN, and then automatically convert to false! View the DEMO.
Simple, right? There will certainly be many people who are thinking the same as me. Why did I not think of it? Why did I not think of it? (Laugh ~)
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.