[Javascript] Banner Ad scripts
Paul Novitski
paul at dandemutande.org
Wed Mar 17 16:37:49 CST 2004
Tim,
Allergic as I am to advertising, how loathe I am to aid in its
proliferation! However, the basic technology can be used for Good as well
as Evil; I leave the choice to you, O Grasshopper.
In addition to what Håkan says generally about the process, I would add
only a few comments on two possible approaches:
1) When the page is rendered, a single item (image & link) appears and
remains fixed for the life of the page. Each time the page is revisited,
the item changes randomly or in rotation.
2) The page contains an item that changes every N seconds, either randomly
or in rotation.
Approach 1) can be handled either server-side or client-side by selecting
from a list of optional items when the page is built. Approach 2) is best
done client-side to avoid a superabundance of network traffic.
I would group the options in an array. Rotating in sequence means keeping
a record of the last element selected, say either in the visitor's cookie
(to create a per-user rotation) or in a master file on the server (for a
site-wide rotation).
You probably know how to select randomly from a list; the approach I
generally use is to multiply the number of items in the list by a random
number (that being a value between 0 and 1) and take the closest integer of
the result. One caveat: the usual random numbers we see never equal zero
or one but merely approach them, and you want to make sure you include the
first & last items in the list. Because we know that the Javascript array
begins indexing with zero and ends with length-1, we can use the Javascript
function Math.floor() that neatly returns the integer less than or equal to
the input value:
var iItem = Math.floor(Math.random() * aItems.length);
DoSomething(aItems[iItem]);
Then of course you can use array values to set the src property for an
image and the href & title properties for an anchor tag.
Paul
At 05:12 AM 3/17/2004, you wrote:
>Does anyone have any advice for good banner-advert cyling scripts -
>basically, I want to set up a rotating series of banner ads on a new
>website, but haven't done this before. Any comments, or recommendations ?
>
>Tim in Ireland.
>
>
>PS Happy St.Patricks Day !!!
>
>_______________________________________________
>Javascript mailing list
>Javascript at LaTech.edu
>https://lists.LaTech.edu/mailman/listinfo/javascript
More information about the Javascript
mailing list