February 24, 2000 - Netscape Navigator's Delayed Printout | WebReference

February 24, 2000 - Netscape Navigator's Delayed Printout

Yehuda Shiran February 24, 2000
Netscape Navigator's Delayed Printout
Tips: February 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

In Internet Explorer you can define a SPAN element and update its content -- all during loading of the page. In Netscape Navigator, this scenario does not work. Netscape cannot write to a SPAN element that has just been loaded. You have to put an event handler that will update the SPAN element when the page is fully loaded.

Let's take for example the Doc Dialer from Column 57. Here is the SPAN element:

<SPAN ID="foundSoFar" STYLE="position: absolute; border: 2px buttonface solid; width: 250"></SPAN>

The event handler in Netscape should be:

onload = start();

And the function start calls another function:

function start() {
  outputStringToDisplay(welcomeStr);
}

And this function does the update:

function outputStringToDisplay(str) {
  if (nameCode == 2) { // netscape
    with (document.foundSoFar.document) {
      open();
      write(str);
      close();
    }
  } 
  else {
    document.all.foundSoFar.innerHTML = str;
  }
}

Learn more about incompatibilities between the browser in Column 6, Browser Compatibility.