DOCJSLIB Version 4.0: Further Streamlining of the HTML Scroller - www.docjavascript.com | 2 | WebReference

DOCJSLIB Version 4.0: Further Streamlining of the HTML Scroller - www.docjavascript.com | 2


Further Streamlining of the HTML Scroller Code

The implementations of the HTML Scroller differ quite a lot between Netscape Navigator and Internet Explorer. The main one is that we implemented the DHTML element with the layer object in Netscape Navigator, and with the in-line frame, <IFRAME> tag, in Internet Explorer. Therefore, the flow in Netscape Navigator is cleaner and simpler. It is all confined to the same scroller script. The flow in Internet Explorer is more complex, as we described in our previous column. The external HTML file includes a small JavaScript piece that is responsible to call the main script.

We have made every effort to remove any browser dependency from the scroller script. These browsers differ, for example, in their support of the onload event for DHTML elements. Internet Explorer does not support it, while Netscape Navigator does. The onElementLoad() function expects three parameters: the element id, the action required, and the parameters needed for this action:

function onElementLoad(element, doThat, theseParameters) {
  if (NS4) eval(element).onLoad = eval(doThat)
  else eval(doThat + theseParameters);
}

As you can see, in Netscape Navigator we translate the function call to an onLoad event handler initialization. In Internet Explorer, we just call the action without any event handling stuff. Here is how the calls to this function look like:

onElementLoad(secondPage, "launchScroller", "()");
onElementLoad(firstPage, "makeSecondPage", "()");

Using such functions helps streamlining the main script, as all browser dependencies are handled in these functions instead of the main script. Another potential streamlining is the conversion of Netscape Navigator's DHTML model to the in-line <ILAYER> tag, which is very similar to the Internet Explorer's <IFRAME> tag. We opted not to do it, as the <ILAYER> tag is notoriously buggy.

http://www.internet.com

Produced by Yehuda Shiran and Tomer Shiran

Created: January 4, 1999
Revised: January 4, 1999

URL: http://www.webreference.com/js/column33/streamline.html