28.4. Handling Multiple Browsers
28.4.1. Checking for Browsers
The first step is to check the browser's name and version number and assign that information to variables. The following code puts the name of the browser in a variable called browserName and the version number in a variable called browserVersion. Depending on the name and number in these variables, the variable browser is assigned a value corresponding to the appropriate browser. Thus, if the browser is Netscape 6, browser is set to nn6; if the browser is IE 4, browser is set to ie4. After the browser identity has been assigned to this variable, you can use if/else statements to ensure that only the correct browser tries to run any browser-specific code:
There are a lot of nuances to browser detection. Fortunately, there are a number of different browser detection scripts available on the Web, so you don't have to create your own. You can find a very thorough one, along with a helpful discussion of its use, at http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html.
28.4.2. Browser Compatibility
Copyright © 2002 O'Reilly & Associates. All rights reserved.