Netscape 6, Part V: DOCJSLIB 1.1: Sniffing the Browser Types - Doc Javascript | WebReference

Netscape 6, Part V: DOCJSLIB 1.1: Sniffing the Browser Types - Doc Javascript


Netscape 6, Part V: DOCJSLIB 1.1

Sniffing the Browser Type

The first change we need to make in DOCJSLIB is sniffing for new browser types. We identify Internet Explorer 4.x by its support of document.all and by its lack of support of document.getElementById:

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

To identify Netscape Navigator 4.x is quite easy: it's the only browser to support document.layers:

var NS4 = (document.layers) ? true : false;

We distinguish Internet Explorer 5.x from the rest of the gang by its support of both document.all and document.getElementById:

var IE5 = (document.all && document.getElementById) ? true : false;

We recognize Netscape 6 and other Mozilla-based browsers by their support of document.getElementById and by their lack of support of document.all. The lack of support of document.all is important because that's one of the unique differentiators between Netscape 6 and Internet Explorer 5.x. Netscape 6's support of document.getElementById is not unique as Internet Explorer 5.x supports it as well.

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

Here is DOCJSLIB 1.1's sniffer in full:

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;

Next: How to use DOCJSLIB's image model

http://www.internet.com


Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: January 29, 2001
Revised: January 29, 2001

URL: http://www.webreference.com/js/column76/3.html