Client-side script for detecting NS6.x and IE5.x without using the navigator object’s properties


The navigator’s object properties are the most common technique used for browser detection.

 

In this post, I am just trying to find an alternate way to do browser detection.

 

A logical alternative would be to use the document object and try to find functions or properties that exist in one browser version but not on another.

 

For example:

 

document.getElementById is available for IE5+ or NS6+

document.all is available for IE4+

 

So, one possible solution would be:

 


if (document.getElementById) { // browser is IE5+ or NS6+
  if (document.all) { // IE4+ only
     // browser is IE5+
  } else {
     // browser is NS6+
  }
}

 

Wondering how this can be useful? Well, who knows if this might come out as one of your interview questions. ;p

 

Leave a Comment

Required

Required (Will not be published)

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed