Rotating Text Banners: Fourth-Generation Browser Detection - Doc JavaScript | WebReference

Rotating Text Banners: Fourth-Generation Browser Detection - Doc JavaScript


Fourth Generation Browser Detection

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:

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


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

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