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:
The JS navigation object contains all information about accessing this browser. Let's take a look at the products of two navigation objects:
AppName-holds the name of the browser
AppName-includes the browser name
AppVersion-holds, among other things, the version of the browser
AppVersion-browser version
Example
Example
<Html> <body> </ptml>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
The variable browser in the example abve holds the name of the browser, I. e. "Netscape" or "Microsoft Internet Explorer ".
In the preceding example, the variable brower (browser) is assigned the browser name, Web View, or IE (or other)
The appVersion property in the example abve 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 we only need the version number. To extract the version number from the string, we use a function called parseFloat () to return the number.
IMPORTANT! The version number is WRONG in Internet Explorer 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.
(About the IE version number returned by JS)
Example
Example
The script below displays a different alert, depending on the visitor's browser:
Depending on the visitor's browser, the following scripts will display different Alerts:
<Html> <pead> </pead> <body onload = "detectBrowser ()"> </body> </ptml>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]