January 23, 2001 - A Short Browser Sniffer | WebReference

January 23, 2001 - A Short Browser Sniffer

Yehuda Shiran January 23, 2001
A Short Browser Sniffer
Tips: January 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

Until Netscape 6 and Internet Explorer 5.x are fully deployed, we need to support Netscape Navigator 4.x and Internet Explorer 4.x. The four lines below identifies which browser you are running on. Internet Explorer 4.x is detected by having the document.all object, and by not supporting the document.getElementById method. Netscape Navigator 4.x is recognized by having the document.layers object. Internet Explorer 5.x has the document.all object and supports the document.getElementById method. Netscape 6 supports the document.getElementById method and does not have the document.all object. Here is the code:

var IE4 = (document.all && !document.getElementById) ? true : false;
var NS4 = (document.layers) ? true : false;
var IE5 = (document.all && document.getElementById) ? true : false;
var N6 = (document.getElementById && !document.all) ? true : false;

Click the button below to find the browser name: