Object Sniffing New Browsers, Part 2: Other Browsers
Object Sniffing New Browsers, Part 2: Other Browsers
In the first article we looked at how utilizing the information a browser sends to your Web server using the user-agent string is problematic, and you could use object detection in order to distinguish between three recent browsers based on the khtml rendering engine, namely: Konqueror, Safari and OmniWeb. We now go one step further by looking at how you can use JavaScript object detection in order to properly distinguish between recent versions of the Netscape browsers.
Why go through the bother of having to identify the browser viewing your site? If you know the type of browsers that hit your Web site, you can better craft your Cascading Style Sheet (CSS) and JavaScript code to take full advantage of the properties and functions that the browser is capable of, and at the same time avoiding known bugs and unsupported properties.
Son of Mozilla
There is little doubt that Netscape 6 was a great improvement over the previous 4.x release, containing far greater standards support for such things like CSS, XML and RDF, along with a much more robust JavaScript architecture. For a long time, the 4.x release of Netscape was the bane of many Web developers, many finding it the lowest common denominator of Web design, especially when Internet Explorer 5.x and 6.0 became dominant. A lot of people sighed a collective sigh of relief when Netscape 6 came out for all the new features it supported, so there were (and are) good reasons to detect this browser in order to take advantage of the features it has to offer.
While not the same quantum leap as its predecessor, Netscape 7 builds upon the developments of version 6, including new and much improved support for things as SOAP, XSLT and access to Web Services via JavaScript. If you're looking to take advantage of any of these features, these are good reasons to want to tell the difference between these two browsers.
The two most recent versions of Netscape are based upon the Gecko rendering engine, first developed for the Mozilla browser, and this fact makes it easy to distinguish both from the version 4.x versions of Netscape. In order to detect the presence of this rendering engine, you just have to look for a match for where navigator.product, as in the following code snippet:
var is_nn6up (navigator.product == 'Gecko')?true:false;
If this statement is true, you are looking at either Netscape 6, 7 or Mozilla.
To tell the differences between them, you need at how the Gecko engine differs between Netscape 6 and 7. Netscape 6 was based upon the Mozilla 0.9 build, and includes a reduced version of the Gecko rendering engine. Netscape 7 was based upon the full Gecko rendering engine available to Mozilla 1.x builds.
In order to tell the difference between Netscape 6 and 7, you can look for the presence or absence of the window.find method, which is used to search the contents of a window for a given string. It is not present in Netscape 6, but is in Netscape 7, so the following two lines will yield different results based on the version of Netscape used:
var is_nn6 (navigator.product == 'Gecko' && !window.find)?true:false;
var is_nn7 (navigator.product == 'Gecko' && window.find)?true:false;
Created: March 27, 2003
Revised: August 12, 2003
URL: https://webreference.com/programming/javascript/sniffing/2