The Navigator object

Although Version 1.1 of JavaScript includes a few new properties, the basic properties of the Navigator object are appName, appVersion, appCodeName and userAgent. For our purposes, the two most important properties are the appName and appVersion properties.

If you guessed that the appName property would hold the name of the application used to view your script, you just might be mistaken, depending on which application was actually being used. Netscape's browsers (both Navigator and Communicator) hold the string value 'Netscape' in the appName property. Internet Explorer, on the other hand, returns the string 'Microsoft Internet Explorer'.

Like the appName property, the implementation of the appVersion property deviates from the most logical behaviour. In Netscape's browsers, the appVersion property is fairly predictable -- the appVersion property holds a string containing the version of the browser in use, followed by the platform and country in parentheses. For example, Netscape Navigator 3 returns '3.01C-NSCP (Win95; I)'.

The '3.01C-NSCP' is the version of the browser, 'Win95' is the platform, and 'I' stands for International version. Microsoft, on the other hand, got a little confused along the way. For IE3, the appVersion property returns a string declaring that the version number is 2.0. However, IE4 returns the following string: '4.0 (compatible; MSIE 4.0; Windows 95)'.

Presumably, IE3's appVersion property returned the version of Navigator that it was compatible with, but then decided that 4.0 sounded better for the appVersion than 3.0 for IE4. Regardless, you can use the following code to redirect program control based on the browser in use:

<script language="JavaScript">
<!--

if(navigator.appName == "Netscape")
	{
	if(navigator.appVersion.charAt(0) == "3")
		alert("Netscape Navigator 3");
	else if(navigator.appVersion.charAt(0) == "4")
		alert("Netscape Navigator 4");
	else
		alert("Unknown version of Netscape");
	}
else if(navigator.appName.substring(0, 9) == "Microsoft")
	{
	if(navigator.appVersion.charAt(0) == "2")
		alert("IE3");
	else if(navigator.appVersion.charAt(0) == "4")
		alert("IE4");
	else
		alert("Unknown Microsoft browser");
	}
else
	{
	alert(navigator.appName.substring(0,9));
	alert("Unknown browser (HotJava maybe?)");
	}

// End script -->
</script>