DHTML Lab - dhtmlab.com - Dynamic Headline Fader, Version 2.01 | 5 | WebReference

DHTML Lab - dhtmlab.com - Dynamic Headline Fader, Version 2.01 | 5


Dynamic Headline Fader, Version 2.01
backward compatibility

The Problem

When Version 2.0 of the Fader appeared a couple of weeks ago, my eagle-eyed editor, Andy King, immediately asked:

Is it compatible with News Harvester?

News Harvester is our Free Headline Service, that could be on your page. But then, you already know that.

The answer to Andy's question, was: "no"

Some History to Make This Page Longer

Fader 1.0

When the original fader was introduced in Column 13, the fader item text display and corresponding URLs were stored in two separate arrays: arTXT and arURL. In a two item fader, the arrays may have looked like this:

arTXT = new Array(
  "High-Speed Hotel Access on the Horizon",
  "Excite Reports Increased Revenues"
arURL = new Array(

NH 1.0

Around the same time, News Harvester was introduced. The headline and link arrays conformed to the fader 1.0 arrays, allowing users to display NH headlines with the fader.

Banners 1.0

Again around the same time, (lots of activity in those days!) Doc JavaScript published his popular Scrolling JavaScript Banners. He also created a version to be used with NH with the arTXT-arURL array scheme.

Hierarchical Menus

When our HM was introduced, a new array scheme was used that combined display text and linked-to URLs into a single array. This format proved successful, as it was less error-prone.

Fader 2.0

Which brings us to the present fader script. By combining the arTXT and arURL arrays into one, arNews, Fader 2.0 was no longer compatible with News Harvester, nor, more importantly, was it compatible with Fader 1.0. Authors who have set up an automatic array-generation engine will not want to rewrite it to generate the new arNews array.

Allowing for the Old Array Scheme

Fortunately, backward-compatibility is easily attained. In Version 2.01, we will need to change the first statement in the FDRinit() function, which returns if the arNews array does not exist:

if (!window.arNews) return;

It now reads:

if(!window.arNews) {
   if(!window.arTXT || !window.arURL) return;
   if(arTXT.length != arURL.length) return;
   arNews = [];
   for (i=0;i<arTXT.length;i++){
      arNews[arNews.length] = arTXT[i];
      arNews[arNews.length] = arURL[i];

In plain English:

We check for the existence of arNews. If we don't find it, we don't assume that there is a load or omission error. We may be dealing with a Fader 1.0 array scheme. So we look for arTXT and arURL. Since both must exist for the fader to function, if either one is missing, we return from the function and no fader is displayed.

If we find both arrays, then we compare their lengths. If they are not the same length, they do not have the same number of complimentary entries, so again, the fader cannot work and we return.

If we find useable versions of arTXT and arURL, we create an empty array, arNews, and fill it alternately with the arTXT and arURL array elements.


When we are done, we have created a Version 2.x compatible array using the old Version 1.0 array scheme. The fader on the left uses the old array scheme, and is displaying NewsHarvester headlines.

Next, let's solve an Explorer-only problem: lack of filters support in the browser.

Produced by Peter Belesis and

All Rights Reserved. Legal Notices.
Created: Sep 21, 1999
Revised: Sep 21, 1999

URL: http://www.webreference.com/dhtml/column25/addendum1/fdr201comp.html