Webmonkey
Powered by Atomz.com



Quick Reference:

• Javascript Code Library
HTML Cheatsheet
Special Characters
Color Codes
Browser Chart
Stylesheet Guide
Unix Guide
Glossary
Domain Registries

Reference   JavaScript Code Library

In order to deal with the many different browsers in use on the Web you need a way for your scripts to tell them apart. Luckily all browsers "announce" themselves with the User-Agent property (see accompanying article), although it can be a pain to keep all the variations apart. The BrowserDetector function isolates the potentially useful portions of the User-Agent string so you can go about the business of making Web pages that work for all browsers.

Usage: var bd = new BrowserDetector(navigator.userAgent);

This will create a new BrowserDetector object named "bd" with the following properties (see the demo page for examples using actual User-Agent strings):

  • bd.browser
  • bd.platform
  • bd.version
  • bd.majorver
  • bd.minorver

Example: The following would redirect users to two different pages depending on whether they were using a version of Netscape or Internet Explorer.

  var bd = new BrowserDetector(navigator.userAgent);
  if (bd.browser == "Netscape") {
    location = "ns_version.html";
  }
  else if (bd.browser == "IE") {
    location = "ie_version.html";
  }

Demo (All JavaScript browsers )

License: Webmonkey Public License

Cut, paste, and enjoy!


Feedback  |  Help  |  About Us  |  Contribute  |  Jobs
Advertise  |  Privacy Statement  |  Terms and Conditions

Copyright © 1994-2000 Wired Digital Inc., a Lycos Network site. All rights reserved.