WebDeveloper.com �: Where Web Developers and Designers Learn How to Build Web Sites, Program in Java and JavaScript, and More!   
Web Developer Resource Directory WebDev Jobs
Animated GIFs
CSS Properties
HTML 4.01 Tags
Site Management
WD Forums

    Web Video
    Expression Web



    Forum, Blog, Wiki & CMS

 Site Management
    Domain Names
    Search Engines
    Website Reviews

 Web Development
  Business Issues

    Business Matters

    The Coffee Lounge
    Computer Issues

HTML Tips and Tricks

by Scott Clark

The Client Is Always Right!

The bleeding edge of the Web is a fickle place to be. Let's face it...these days you're either designing for fans of Netscape Navigator or those of Microsoft Internet Explorer. Both browsers understand much of the same HTML tags (with the exception of a few browser-specific tags such as BGSOUND, EMBED and MARQUEE), but now the explosion of new HTML tags and scripting functions has gotten to the point that developers are asking themselves not only what browser, but what version of the browser are my clients using?

Fortunately, you can detect the exact browser type and show an appropriate page using JavaScript. You can also use CGI to do the same thing, so we'll explore both methods and let you decide which is more efficient for your site. Of course, using both methods also has its advantages, as you'll soon see.

The latest versions of both Navigator and Internet Explorer are able to interpret JavaScript code (although IE uses its own version of JavaScript called JScript). While there are several differences between JavaScript and JScript, both versions can utilize the Navigator object. The JavaScript Navigator object is used to find information about the user's browser. The Navigator object has four properties: appCodeName, which specifies the code name of the browser; appName, which specifies the name of the browser; appVersion, which specifies version information of the browser; and userAgent, which specifies the user-agent header.

Using the navigator.userAgent, for instance, I can get the value that was sent by the client in the user-agent header that identifies the type of browser (i.e. Mozilla, Netscape's code name), version, and the platform that the client is running. Obviously this information can come in very handy. There are a lot of great new JavaScript techniques (Image objects, mouseOut, etc.) that can only be used if the client is running Navigator version 3.0 or greater. If a client doesn't have it, you want them to see a page that works for the version they're using. The JavaScript code that can accomplish that looks like this:

 <SCRIPT LANGUAGE = "JavaScript"> var version = 0; if (navigator.userAgent.indexOf("Mozilla/3.0") != -1)version = 3; else if (navigator.userAgent.indexOf("MSIE") != -1) version = 1; else if (navigator.userAgent.indexOf("Mozilla/2.0") != -1) version = 2; else version = 0; function browser_type() {
if (version == 3) return "Netscape Version 3.0"; if (version == 2) return "Netscape Version 2.x"; if (version == 1) return "Microsoft Internet Explorer 3.0"; if (version == 0) return "an off-the-wall JavaScript browser";

[ Click here to move to the next part of the article ]

Web Developer® Site Feedback
Web Developer®
Copyright © 2000 internet.com Corporation. All rights reserved.

HTML5 Development Center

Recent Articles