Invalid Domain

You are here :



Quick Reference:

Javascript Code Library
HTML Cheatsheet
Special Characters
Color Codes
Browser Chart
Stylesheet Guide
Unix Guide

JavaScript Code Library
user_interface
BrowserDetector()
by Dr. Richard Blaylock

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, 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 )

Cut, paste, and enjoy!

SUBMISSIONS
If you have code to share with other Webmonkeys, send it our way.

Can't find something?
Check out the
JavaScript archive