Scrolling JavaScript Banners: Assigning the Messages - Doc JavaScript | WebReference

Scrolling JavaScript Banners: Assigning the Messages - Doc JavaScript

Assigning the Messages

The banner displays a set of messages by rotating them in a predetermined order. We'll use an array to specify the HTML code for each message. Note that a message may consist of plain text, links, images, or any other valid code. We recommend text-based messages, including hypertext links, because text loads much faster than images.

All messages should have a similar format. We'll use one-line text messages to demonstrate. Here's the definition of the array:

var ar = new Array(
  '<A HREF="/js/column1/">Universal JavaScript Rollovers</A> - <I>Rx #1</I>',
  '<A HREF="/js/column2/">Mastering JavaScript Dates</A> - <I>Rx #2</I>',
  '<A HREF="/js/column3/">Rotating Text Banners</A> - <I>Rx #3</I>',
  '<A HREF="/js/column4/">Text Rollovers</A> - <I>Rx #4</I>',
  '<A HREF="/js/column5/">Regular Expressions</A> - <I>Rx #5</I>',
  '<A HREF="/js/column6/">Browser Compatibility</A> - <I>Rx #6</I>',
  '<A HREF="/js/column7/">Window Spawning and Remotes</A> - <I>Rx #7</I>',
  '<A HREF="/js/column8/">Crispy JavaScript Cookies</A> - <I>Rx #8</I>',
  '<A HREF="/js/column9/">The Navigator Event Model</A> - <I>Rx #9</I>',
  '<A HREF="/js/column10/">The Internet Explorer Event Model</A> - <I>Rx #10</I>',
  '<A HREF="/js/column11/">The Cross-Browser Event Model</A> - <I>Rx #11</I>',
  '<A HREF="/js/column12/">JavaScript Selections</A> - <I>Rx #12</I>'

As you can see, each array element is a string containing the HTML code necessary for the message. Any HTML definitions can be included in the messages.

The messages are assigned to the array's elements when the array is created. When you specify LANGUAGE="JavaScript1.2" in the <SCRIPT> tag, the Array() constructor assigns its arguments to the new array's elements. In Navigator 3.0x, for example, the Array() constructor accepts one argument, which specifies the length of the array. The Array() function in Internet Explorer 4.0x, as in Navigator 4.0x, creates the new array and then assigns its arguments to the array's elements. The script's LANGUAGE="JavaScript1.2" attribute ensures that only Navigator 4.0x and Internet Explorer 4.0x execute the script, so the array is properly defined. The next section of the column lists the entire code for the bannerconfig.js file.

Created: February 10, 1998
Revised: February 10, 1998