★ wanayoo — archive 1999 http://www.webdeveloper.com/javascript/javascript_auto_optimize.htmlNouvelle recherche | Portail wanayoo
internet.com

Go to WebDeveloper Home

Seek and you shall

or search all of internet.com
Looking for a Site Map?
Vote for WD!
Please keep
voting for us
as a Top 100
Web site!

The Web Developer Network
WebDeveloper.com
Streaming Media World
WebReference.com
Web Developer's Virtual Library
BrowserWatch
Java Boutique
Web Developer's Journal
JavaScript Source
ScriptSearch
Web Developer Forums
Web Developer News

internet.com
Internet News
Internet Stocks
Internet Technology
Web Developer
Internet Marketing
ISP
Downloads
Internet Resources
International

Search internet.com
Advertising Info
Corporate Info
Internet Trade Shows

internet.commerce
Be an Affiliate
Be a Partner
Software Store
Computer Help
Register a Domain
Be Domain Registrar
e-solutions
Internet Jobs
A/V Network
Map Your Website
Rent E-mail Lists
Bookstore
Press Release dist.
Sell Ad Space
Internet Research
Venture Capital
Web Publishing
Build Your Intranet
Expert Advice
Get e-Biz Intell.
Content for Websites

Web Marketers' Online Facts Library

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";
} </SCRIPT>

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


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

http://www.internet.com
Web Developer® Home Over a dozen topics in detail Live Chat Downloads Book and Product Reviews Threaded Discussions How-To/Articles/Links Developer Daily News Subscribe Search Corporate Information Advertise Events Publications internet.com Home