JavaScript Advanced Programming Chapter Nineth-client-side detection

Source: Internet
Author: User

JavaScript Advanced Programming Chapter Nineth-client-side detection
Client-side detection is one of the most controversial topics in JavaScript development, and due to differences between browsers, it is often necessary to
To write different code separately. The following commonly used client detection methods are available:
Capability Detection: Detects the ability of a particular browser before writing code. For example, a script might want to detect a function before calling it
is present. This approach frees developers from thinking about specific browser types and versions, allowing them to focus on the appropriate
The ability to exist. Capability detection is not able to detect specific browsers and versions accurately.
Quirks detection: Quirks are actually bugs in the browser, such as a quirk in the early WebKit, which returns to the For-in loop
Back to the property that was hidden. Quirks detection usually involves running a small piece of code, and then determining whether the browser has a quirk, and the quirks detection efficiency is
Low, only used in situations that interfere with scripting, and quirks detection does not accurately detect specific browsers and versions.
User Agent Detection: The browser is identified by detecting the user agent string. The user agent string contains a large number of browser-related information, the package
Platforms, operating systems, and browser versions. The user agent string has a long history of development, during which the browser provider tries to
By adding some deceptive information to the user agent string, the figure deceives the site to believe that its browser is a different browser. User Agent detection is required
For special tricks, pay special attention to the case where open hides its user-agent strings. Even so, the user agent string can still be checked
Detects the rendering engine used by the browser and the platform on which it resides, including mobile devices and game systems.
When deciding which client-side detection method to use, a general preference is given to the use of capability detection. Quirks detection is the second that determines how code should be handled
Selection, and user agent detection is the last scenario for client-side detection, because this method is highly dependent on the user-agent string.

JavaScript Advanced Programming Chapter Nineth-client-side detection

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.