spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column3


Fourth Generation Browser Detection

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

Our script utilizes JavaScript 1.2, first supported by Navigator 4.0x and Internet Explorer 4.0x, so we must make sure it does not affect users with older browsers.

There are two ways to determine which browser the user is running:

  • You can evaluate navigator.appVersion or navigator.userAgent.
  • You can check if the browser supports specific objects (or properties) that the script requires.

The following script creates two Boolean variables that indicate whether the user is running Navigator 4.0x (or above) or Internet Explorer 4.0x (or above):

<SCRIPT LANGUAGE="JavaScript">
<!--

var bName = navigator.appName;
var bVer = parseInt(navigator.appVersion);
var NS4 = (bName == "Netscape" && bVer >= 4);
var IE4 = (bName == "Microsoft Internet Explorer" && bVer >= 4);

// -->
</SCRIPT>

The following script does the exact same by checking if the browser supports specific objects:

<SCRIPT LANGUAGE="JavaScript">
<!--

var NS4 = (document.layers) ? 1 : 0;
var IE4 = (document.all) ? 1 : 0;

// -->
</SCRIPT>

NS4 is true if the browser supports the document.layers object. In other words, it is true for Navigator 4.0x. The second variable, IE4, is true if the browser supports the document.all object. That is, it is true for Internet Explorer 4.0x. Note that 1 and 0 are equivalent to true and false. We use them because they are shorter.

We'll use the second detection method in our scripts. By evaluating NS4 and IE4 we can find out if the user is running a fourth-generation browser:

<SCRIPT LANGUAGE="JavaScript">
<!--

var NS4 = (document.layers) ? 1 : 0;
var IE4 = (document.all) ? 1 : 0;
if (IE4 || NS4)
  document.write("This is a fourth-generation browser!");

// -->
</SCRIPT>

This script simply prints "This is a fourth-generation browser!" if the user is running Navigator 4.0x+ or Internet Explorer 4.0x+.

http://www.internet.com

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint


Created: September 25, 1997
Revised: April 16, 1998

URL: http://www.webreference.com/js/column3/detection.html