Identify the Browser Based on Feature Detection in the shortest

Source: Internet
Author: User

Note: We generally discuss IE and non-ie browsers here. More precise detection needs to be combined with UA and other features for Comprehensive Judgment.

1. Vertical Tab

'\ V' escape problem, using the browser to understand the Escape Character' \ V'

The IE browser cannot recognize \ v as an escape character and directly outputs v

Other browsers (currently verify safari \ chrome) escape to vertical tabs, which is roughly equivalent to "" a space

// IE will generate V1, right-expression + will be converted to String concatenation, but left-expression is empty, will be converted to Number Addition, you can understand why + [] is equal to 0 // so the result of IE + "V1" is nanvar Ie =! + "\ V1"; // false, ie

2: Use the JS engine of the browser to parse different

When we write the JS object of an object with a JSON-like structure, such

{  name: "test",  key: "key",  value: false,}

The error message of this Code in IE engine is: Unexpected Terminator, because the parsing error of ',' browser after the value ends, therefore, this method makes full use of the browser's error correction function for judgment.

Then [1,] the tostring method called by IE will parse "1," and remove ',' in the standard browser. Note that [, 3, 4,] in the arraylist are distinguished. which indexes are missing? See the description of MDN.

If (! + [1,]) {// ie} else {// standard browser} // operator + when the left expression does not exist, it will try to convert the right expression to number // + [] // + [] the conversion process can be explained in this way // number ([]) // number ([]. tostring () // []. valueof () isn' t primitive // number ("") // 0

Extension: + [] can be viewed

Identify the Browser Based on Feature Detection in the shortest

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.