spacer
Yehuda Shiran November 25, 2000
Sniffing for Netscape 6
Tips: November 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Google Chrome Playing Catch-Up on Extensions
Open Solutions Alliance Gets New Leadership
Red Hat Spacewalk Expands Linux Management
The most common pattern in JavaScript scripts is probably the section that determines the browser type. And its structure is probably something like:

<SCRIPT LANGUAGE="JavaScript">
<!--
if (document.all) {
  document.write("Internet Explorer Detected");
}
else if (document.layers) {
  document.write("Netscape Navigator Detected");
}
else {
  document.write("Unrecognized Browser Detected");
}
// -->
</SCRIPT>

Try this script. Convince yourself it's working as expected in Internet Explorer and in Netscape Navigator. Try now in Netscape 6. You should get the "Unrecognized Browser Detection" message. Netscape 6 does not support document.all, nor does it support document.layers. See tip 001124. Netscape 6 supports document.getElementById. But Internet Explorer supports this method as well, so you need to be careful how to write your new browser sniffer. See Webreference's updated sniffer. The script above should look like this now:

<SCRIPT LANGUAGE="JavaScript">
<!--
if (document.all) {
  document.write("Internet Explorer Detected");
}
else if (document.layers) {
  document.write("Netscape Navigator Detected");
}
else if (document.getElementById) {
  document.write("Netscape 6 Detected");
}
else {
  document.write("Unrecognized Browser Detected");
}
// -->
</SCRIPT>

Try this script. Notice the positive identification of Netscape 6.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

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

webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags