Sidebar


Browser Detection in JavaScript 1.1

JavaScript is commonly used to increase your Web site's interactivity. To get the most bang for the buck, it helps to know which browser your visitor is using. And with the introduction of Communicator (Navigator 4.0), it's even more important to know which version of Navigator is being used. With this knowledge, you can display the appropriate pages for the appropriate browser. Listing Nine handles both Internet Explorer and Netscape browsers.

In JavaScript, an object called navigator displays information about the browser you are using (name, version number, and so on). The first if statement in Listing Nine looks to see if the browser is a Netscape browser using this object. If so, I use the appVersion property, which displays the browser's version number and the platform. Next, I use the substring() method to only get the version number. For each version, I redirect the user to a specific page set up for that particular browser. Redirection is accomplished by pointing the window.location property to different HTML pages.

Reaz is a speaker, Web developer, and author of the Practical JavaScript Programming Book. Visit his home page at rhoque.com.