|
var sPlatform = navigator.platform.substring(0,3).toUpperCase(); |
||
|
|
||
|
Or can we? Unfortunately, no. The platform property is available only on version 4 and above browsers. So we will have to go back to our trusty appVersion property. For backwards compatibility, we can find the platform with the following: |
|
var sPlatform = navigator.appVersion.toUpperCase(); sPlatform = (sPlatform.indexOf("WIN") >= 0) ? "WIN" : (sPlatform.indexOf("MAC") >= 0) ? "MAC" : "OTHER"; |
||
|
|
||
|
If we put everything together, we end up with: |
|
var sBrowser = (navigator.appName.indexOf("Netscape") >= 0) ? "NS" : (navigator.appName.indexOf("Microsoft") >= 0) ? "IE" : "OTHER"; var sVersion = parseFloat(navigator.appVersion) + ""; if (sBrowser == "IE") { var iInfo = navigator.appVersion.indexOf("MSIE ") + 5; var sInfo = navigator.appVersion.substring(iInfo); sVersion = parseFloat(sInfo) + ""; } var sPlatform = navigator.appVersion.toUpperCase(); sPlatform = (sPlatform.indexOf("WIN") >= 0) ? "WIN" : (sPlatform.indexOf("MAC") >= 0) ? "MAC" : "OTHER"; |
||
|
|
||
Note: all information (including sVersion) is maintained in strings. You can now go on to create whatever variables you want to test for and use in the rest of your page. But then, why go to all this trouble when, for most instances, there is a more direct route: sniffing by functionality. Continue |
| © 1999
bnsDesigns |