The Navigator Object
Navigating objects
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 the information about accessing this browser. We'll look at the products of two navigation objects:
Appname-holds the name of the browser
AppName-Contains the name of the browser
Appversion-holds, among other things, the version of the browser
AppVersion-Browser version
Example
Example
<ptml><body> <script type= "Text/javascript" > var browser=navigator.appname var b_version=navigator . appversion var version=parsefloat (b_version) document.write ("Browser name:" + Browser) document.write ("") document. Write ("Browser version:" + version) </script> </body></ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
The variable browser in the example above holds the name of the browser, i.e. "Netscape" or "Microsoft Internet Explorer".
In the example above, 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 this contains much more information than just the version Nu Mber, but for now we are only interested in the version number. To pull the "string" We are using a function called parsefloat (), which pulls the "the" Looks like a decimal number out of a string and returns it.
The AppVersion property in the example above returns a string of information characters that contain more than the version number, but now we just need the version number. To present the version number from a string we use a function called parsefloat () to return the 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??? However, JavaScript is the same in IE6, IE5 and IE4, so for most scripts it are OK.
(about JS back to IE version number of problems)
Example
Example
The script below displays a different alert, depending on the visitor ' s browser:
Depending on the visitor's browser, the following script will display a different alert:
<ptml> <pead> <script type= "Text/javascript" > function Detectbrowser () {var browser=navigator.appname var b_version=navigator.appversion var version=parsefloat (b_ Version) if (browser== "Netscape" | | browser== "Microsoft Internet Explorer") && (version>=4)) {alert ("Your browser is Good enough!")} else {alert ("It ' s time to upgrade your browser!")}} </script> </pead><body onload= "Detectbrowser ()" > </body> </ptml>
Input onclick= "RunEx (' runcode9964 ')" type= "button" value= "Run Code" > [ctrl+a All selected note: If you need to introduce external JS need to refresh to perform]