<!-- This example is from the book _JavaScript: The Definitive Guide_. --> <!-- Written by David Flanagan. Copyright (c) 1996 O'Reilly & Associates. --> <!-- This example is provided WITHOUT WARRANTY either expressed or implied.--> <!-- You may study, use, modify, and distribute it for any purpose. --> <SCRIPT> // Return the version number times 1000. This means that version // 2.02 would yield 2020, and version 3.0 would yield 3000. // We multiply because Navigator versions 2.0x convert numbers like // 2.02 to strings like "2.0199999999875" function _get_version() { return Math.round(parseFloat(navigator.appVersion) * 1000); } // Figure out the OS we are running on, based on the appVersion property function _get_os() { if (navigator.appVersion.indexOf("Win95") > 0) return "WIN95"; else if (navigator.appVersion.indexOf("Win16") > 0) return "WIN31"; else if (navigator.appVersion.indexOf("Mac") > 0) return "MAC"; else if (navigator.appVersion.indexOf("X11") > 0) return "UNIX"; else return "UNKNOWN"; } // Create the object we'll use to store the version information. var browser =index.html new Object(); // First, check if it is a Netscape browser. if (navigator.appName.substring(0,8) == "Netscape") { // if so, set the name variable appropriately browser.name = "NN"; // then parse navigator.appVersion to figure out what version browser.version = _get_version(); // Then use appVersion again to determine the OS. browser.os = _get_os(); } // Otherwise, see if it is a Microsoft browser. // // If so, we set all the variables directly, because MSIE only has // one JavaScript-enabled version, and it only runs on one platform. // We don't use Navigator.appVersion to compute the version number, because // it returns a Netscape-compatible value of 2.0 rather than the true // MSIE version number 3.0. We don't use it to compute the OS, because // MSIE encodes that information with different strings than Navigator // does, so we can't use the _get_os() function above. // // This code will have to be updated when a new version of MSIE is released // but we'll have to wait and see how MS encodes the information in the // various Navigator object properties we can update the code. else if (navigator.appName.substring(0,9) == "Microsoft") { browser.name = "MSIE"; browser.version = 3000; browser.os = "WIN95"; } // Otherwise, it is some unknown browser that supports JavaScript. // So we try to guess the browser name, version number and os, assuming // that this browser stores the information in the same format as Navigator. else { browser.name = navigator.appName; browser.version = _get_version(); browser.os = _get_os(); } // Now figure out what version of JavaScript is supported by the browser. // Start by assuming that only version 1.0 is supported. browser.langlevel = 1000; </SCRIPT> <SCRIPT LANGUAGE="JavaScript1.1"> // if the browser supports JavaScript 1.1, update the langlevel variable browser.langlevel =index.html 1100; </SCRIPT> <SCRIPT LANGUAGE="JavaScript1.2"> // if the browser supports JavaScript 1.2, update the langlevel variable browser.langlevel =index.html 1200; </SCRIPT>
file: /Techref/language/JAVA/script/definitive/examples/13.1.txt, 3KB, , updated: 1997/4/4 10:59, local time: 2024/11/30 07:02,
18.116.85.102:LOG IN
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://ecomorder.com/Techref/language/JAVA/script/definitive/examples/13.1.txt"> language JAVA script definitive examples 13</A> |
Did you find what you needed? |
Welcome to ecomorder.com! |
Welcome to ecomorder.com! |
.