JS's Navigator Object

Source: Internet
Author: User

The Navigator property of the Window object refers to the Navigator object that contains the browser manufacturer and version information. The Navigator object was named to commemorate the Netscape after Navigatorbu 2, but all other browsers also support it (ie also supports clientln formation attribute, which is synonymous with navigator's vendor neutrality
Word. Unfortunately, other browsers do not support this more intuitive property naming. In the past, navigator objects were often used by scripts to determine whether they were running in IE or in Netscape. This browser sniffing method is problematic because it requires the introduction of new browsers and new versions of existing browsers to continually
Adjustment. Today, there is a better method of functional testing (see section 13.4.3), which requires only testing the required functionality (i.e., methods or properties) rather than setting up specific browser versions and their functions. However, browser sniffing is still valuable at times. One such scenario is when you need to address a particular
Special bug in a specific version of the browser. The Navigator object has 4 properties that provide information about the version of the browser that is running, and you can use these properties for browser sniffing.

AppName
The full name of the Web browser. In IE, this is Microsoft Internet Explorer. In Firefox, this property is "Netscape". In order to be compatible with existing browser sniffing code, other browsers often also value "Netscape".
appversion
This property typically starts with a number, followed by a detailed string containing the browser vendor and version information. The number in front of the string is usually 4.0 or 5.0, indicating that it is a 4th or 5th generation compatible browser. The appversion string does not have a standard format, so there is no way to use it directly to determine the type of browser.
useragent
Browser. The string that is sent in its user-agent HTTP header. This property usually contains all the information in the appversion, and often may contain other details. And appversion--like, it also has no standard format. Because this property contains most of the information, browser sniffing code usually uses it to sniff.
platform
A string on which to run the browser's operating system (and possibly hardware). The complexity of the Navigator attribute is an indication that browser sniffing is not very helpful in dealing with client compatibility issues. In the early days of the web, people wrote a lot of browser-specific code to test properties similar to Navigator.appname
. When developing a new browser, browser vendors find that to make the existing sites appear correct, they need to set the appname to "Netscape". Similar practices make AppVersion's starting numbers meaningless, and now browser sniffing code must rely on navigator.useragent strings that are much more complex than before.
Example 14-3 shows how to use regular expressions (excerpted from IQuery) from navigator. The method of extracting the browser name and version number from the useragent.

Example 14-3: Browser sniffing using navigator.useragent~-//For client sniffing define Browser.name and browser.version, where the code in Jouery l.4.1 is used// Both the name and number are strings, and the results for different browser outputs are not the same, and the results are as follows: j|//"WebKit": Safari or Chrome; version number is WebKit version number//"opera": Opera; Version number is the version number of the SOFTWARE//"Mozilla": Firefox or other browser based on Gecko kernel, version number is Gecko Version//"MSIE": IE; version number is the version of the software | | For example, Firefox 3.6 returns: {name: "Mozilla", Version: "1.9.2"}var browser= (function () {var s=navigator.useragent.tolowercase () var match=/(webkit) [\/] ([\w.] +)/.exec (s) | | /(opera) (?:. *version)? [\/] ([\w.] +)/.exec (s) | | /(MSIE) ([\w.] +)/.exec (s) | | /compatible/.test (s) &&/(?:. *RV: ([\w.] +))?/.exec (s) I l[];

JS's Navigator Object

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.