Persistent Random Banners: Building the Message Feed | WebReference

Persistent Random Banners: Building the Message Feed


Persistent Random Banners

Building the Message Feed

The message feed is an array of messages, tips, stored in an external file, feed.js. Each member of the array is a message written in an HTML format. You can include any HTML construct like links (<A>...</A>), images (<IMG ...>), and new lines (<BR>). In this column, the feed includes promotions for past tips. Here is one of them:


tips[34] = 'Are you familiar with the DOM\'s Cloning Depth?
          <A HREF="/js/tips/000324.html">
          Learn how to manipulate the whole tree or just
            its root</A>.';

Notice that you have to escape the quote characters with backslashes as we did above in DOM\'s. Here are ten more example tips:


tips[0] = '<A HREF="/js/tips/990923.html">Learn how</A> to load
           a new page while disabling the browser\'s \"Back\"
           function, so the user has no way back.';
tips[1] = 'Do you want to display an eye-catching true color image?
           <A HREF="/js/tips/990924.html">Find out how</A> to select
           an optimized image for your user.';
tips[2] = '<A HREF="/js/tips/990925.html">Find out how</A> to
           generate a random number, so you can load a random Web
           page or display a random message.';
tips[3] = 'Do you want to access various properties and methods of
           the same object? <A HREF="/js/tips/990926.html">You
           don\'t need to repeat the object reference</A>.';
tips[4] = 'How about speeding up your Web site?
           <A HREF="/js/tips/990927.html">Find out how</A> to
           preload your images with JavaScript.';
tips[5] = 'Be sure you are getting real email addresses, not useless
           garbage. <A HREF="/js/tips/990928.html">Check out</A>
           an advanced cross-browser solution.';
tips[6] = 'Is your script ready for the next millennium?
           <A HREF="/js/tips/990929.html">Be sure</A> you\'ve
           nailed down the Y2K issues.';
tips[7] = 'Do you want to share libraries between HTML pages?
           <A HREF="/js/tips/990930.html">Learn how to</A> do it
           with external script.';
tips[8] = 'Do you want old browsers be able to load your page?
           <A HREF="/js/tips/991001.html">Learn how</A> to hide
           the script from them.';
tips[9] = 'Do you know how to use the null value?
           <A HREF="/js/tips/991002.html">Learn how</A> to take
           advantage of it.';

The message feed, feed.js, includes 35 messages, starting with tips[0] and ending with tips[34]. The number of messages that will be actually displayed depends on the parameter value with which you call refreshDocJSTOD(). Calling it with "now" will ensure that, although the order will be random, every message will be actually displayed eventually. For other values of frequency the number of messages pulled out of the total available pool in feed.js is as follows:

Next: The Code

https://www.internet.com

Produced by Yehuda Shiran and Tomer Shiran

Created: March 27, 2000
Revised: April 26, 2000

URL: https://www.webreference.com/js/column60/4.html