Netscape 6, Part I: Detection and Scripting Page 3

By Yehuda Shiran (Send Email)
Posted Dec 5, 2000

Download the authoritative guide: Data Center Guide: Optimizing Your Data Center Strategy

Download the authoritative guide: Cloud Computing: Using the Cloud for Competitive Advantage

The introduction of Netscape 6 has worsen the browser-independent scripting situation, at least for the short time. No longer do you have to deal with only two browsers - there are now three major browsers to support. One good old way is to use if statements. You want to make your script as generic as possible, and use if clauses as late as possible. The following script uses this technique. The switchEntries() function is a common event handler for all browsers. The content of switchEntries() is an if statement that executes a different statement for every browser:

<FORM NAME="election">
<SELECT NAME="presidents">
<OPTION NAME="leaving">Al Gore
<INPUT TYPE="button" VALUE="Switch first option" onclick="switchEntries()">
function switchEntries() {
  if (document.all) {
    document.election.presidents.item(0).text = 'Bill Clinton';
  else if (document.layers) {
         document.election.presidents[0].text = 'Bill Clinton';
       else if (document.getElementById) {
              document.election.leaving.text = 'Bill Clinton';
// -->

Click the button below to see how the first option changes on the fly:

Avoiding Netscape's Proprietary Features

Netscape 6 does not support the LAYER and ILAYER elements. It means that the browser will silently ignore the <LAYER>, </LAYER>, <ILAYER>, and </ILAYER> tags. The browser will render the HTML page as if those tags are not present. Any other elements (non-LAYER) between <LAYER> and </LAYER> will be rendered as if the <LAYER> and </LAYER> are missing. Obviously, this will change the look of the page. Let's take an example. The following LAYER element includes one line of text:

In Netscape Navigator, this line should be colored tan. Should be white in Netscape 6 and IE.

Here is the rendering of this element on your browser:

In Netscape Navigator, this line should be colored tan. Should be white in Netscape 6 and IE.

Thanks for your registration, follow us on our social networks to keep up-to-date