BROWSER
DETECTION SCRIPT IN JAVASCRIPT –
|
The javascript that will detect the browser makes use of the navigator object.
This object holds these interesting variables:
|
The following information was derived from your browser when you arrived on this page:
navigator.appCodeName
|
|
navigator.appName
|
|
navigator.appVersion
|
|
navigator.userAgent
|
|
navigator.platform
|
|
In short, all we need to do is have the webpage run our script once it's loaded.
This is done by simply writing the javascript code without function declarations.
The following lines should be added to the section of the document:
BROWSER DETECTION SCRIPT - Step 2/3
|
The above lines store the name of the browser in the variable called browsername.
If the browser is Microsoft Internet Explorer, "MSIE" is stored in the variable.
If it is a Netscape browser, "NS" is stored in the variable.
If it's none of the above, "N/A" is stored in the variable.
|
Now we need to find the version of the relevant browser.
Since navigator.appVersion does not simply hold a value, like 2, 3 or 4, but rather would hold a text, like "3.0b4Gold (Win95; I)", we need to make a little check of the text before we can save a more convenient value in the variable called browserversion.
|
First we assign the value zero to the variable.
If none of the checks results in assigning a value to the variable, it will still hold the zero value after the checks.
A value of zero thus means that the browserversion
was not available.
The next 3 lines look for version numbers 2., 3., 4. and 5.
If navigator.appVersion contains any of the numbers, the value is stored in the variable called "browserversion".
The complete script now looks like this:
BROWSER DETECTION SCRIPT -
|
No comments:
Post a Comment
Comment Here