A little understanding, specific use can be re-read data. In order to eliminate differences between browsers. Do not use the customer detection method at a specific time, should give priority to the general method, and then consider the browser particularity. Ability detection (feature detection), quirks detection (browser bug), User agent detection (not recommended) capability testing (feature detection)
- Detects if the browser has an attribute (capability) to use the feature or ability to do the next step. The goal is not to detect the browser but to detect whether it supports specific capabilities.
- Often the most commonly used features are detected at the beginning (which can effectively avoid wasting time), and to avoid logical problems (such as the existence of an attribute, then another logical correlation)
- Reliable Capability Detection logic:
- Test with TypeOf, although TypeOf sometimes have problems
- Capability detection, rather than browser detection, is best combined with the ability to detect all relevant features at once, depending on the browser's differences.
- Still note the evolving and changing browser:
- The same browser, once unsupported, the new version does not necessarily do not support
- The same browser, once supported, the new version does not necessarily support
- Different browsers, once a browser-specific features or writing, perhaps another browser also started to support (so do not judge the browser, but to determine the characteristics)
Quirks detection
- Identify the special behavior of the browser, what quirks (bugs). Run the code to determine that a feature is not working correctly.
- There is no need for a specific object, run the detection function directly to get the result.
- It is a good idea to perform such tests at the beginning of the script to detect quirks that have a direct impact on the current program.
User Agent Detection
- Principle: In an HTTP request, the user-agent string (which can be used to determine the user's actual browser) is sent as the header of the response, which can be accessed through the Navigator.useragent property in JS.
- Server, it is common practice to determine the browser through a proxy string, but the client is controversial and prioritized after capability detection and quirks detection.
- History of the user agent string (Why this detection is required, spoofing)
- Spoofing: The browser deceives the server by adding false or misleading information to its own user-agent string.
- Rule: identifier/PRODUCT version number---> actual more complex
- Example of spoofing: a new browser for a compatible platform, disguised as an already ubiquitous browser (ie disguised as Mozilla)
- User-agent string detection technology: Obviously not easy
- Identify the rendering engine (better than knowing the name and version number of the browser) IE, Gecko, Webkit, Khtml, Opera
- Detection order is important: Opera>webkit (contains "khtml", "Gecko") >khtml ("Gecko") >gecko>ie
- For example, the first step is to detect opera, because it will only pretend to be another engine, while other engines will not normally disguise it (based on the history of the user-agent string in the previous section).
-
- Identify browser (render engine-->JS engine/browser type): Add Browser object in Client
- Identify platform (Windows, Mac, Unix): Add a System object to the client Navigator.platform
- Identify the Windows operating system:
- Identify mobile devices
- Identify game systems
- The full code is in the PDF P261 page 9.3.3 Section
method of use (not used when necessary)
- The last choice of client detection, capability detection and arm detection is better than it
- When the first two tests cannot be used directly and accurately (the first two tests do not get enough information)
- The same browser with different capabilities under different platforms (when it is really necessary)
- Need to know the exact browser for the purpose of tracking analysis (IBID.)
JavaScript Advanced Programming Chapter 9 Client detection