The Navigator Object
Navigation object
The JavaScript Navigator object contains all information about the visitor's browser. We are going to look at two properties of the Navigator object:
JS Navigator object contains all information about the visitor's browser. information. We'll look at the product of two navigation objects:
appName - holds the name of the browser
appName - holds the name of the browser
appVersion - holds, among other things, the version of the browser
appVersion - browser version
Example
Example
]
The variable browser in the example above holds the name of the browser, i.e. "Netscape" or "Microsoft Internet Explorer".
In the above example, the variable brower (browser) is assigned the name of the browser, Netscape or IE (or other)
The appVersion property in the example above returns a string that contains much more information than just the version number, but for now we are only interested in the version number. To pull the version number out of the string we are using a function called parseFloat(), which pulls the first thing that looks like a decimal number out of a string and returns it.
The appVersion attribute in the above example returns a string containing more information characters than the version number, but now All we need is the version number. To extract the version number from a string we use a function called parseFloat() which returns a number.
IMPORTANT! The version number is WRONG in IE 5.0 or later! Microsoft start the appVersion string with the numbers 4.0. in IE 5.0 and IE 6.0!!! Why did they do that??? However, JavaScript is the same in IE6, IE5 and IE4, so for most scripts it is ok.
(Regarding the problem of JS returning IE version number)
Example
Example
The script below displays a different alert, depending on the visitor's browser:
The following script will display different alerts depending on the visitor's browser:
If you need to introduce external Js, you need to refresh to execute ]
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn