Topic Areas
Free Scripts
Information
Resources
Tutorials
Information
Search
Help Forums
Contact
Link to Us
Submit Script
Privacy Policy
More Resources
Free Stuff
Web Resources
Other Links
PageResource.com: Learn HTML
Just Free Stuff
JavaScript City
Random Banner Display

Script Introduction

This script will allow you to display a random banner from a set of 5. Each banner will be linked to a url of your choice, so this can be used for a random banner ad rotation. You have some display options such as border size, centering, and the banner size. ( All banners in the set must be the same size, though ).

Cut and Paste Code: HEAD Section
This code should be placed between the <head> and </head> tags.

Cut and Paste Code: BODY Section
This code should be placed between the <body> and </body> tags.

Installation Instructions

  1. Paste the HEAD Section code from above between the <head> and </head> tags on your page.
  2. Paste the BODY Section code from above between the <body> and </body> tags on your page, exactly where you want the banner to appear.

  3. Change the text in red below to the appropriate image addresses and link url addresses for your site. Change the options at the top of the script to adjust the appearance of your banners.

    pic_width=468; /*change to match the height of all your images */
    pic_height=60; /* change to match the width of all your images */
    border_size=0; /* change to the border size you want on the images */
    alignment=1; /* 0=left,1=center */

    /* define image urls */

    if (document.images)
    {
    pic1= new Image(pic_width,pic_height);
    pic1.src="image1.gif";
    pic2= new Image(pic_width,pic_height);
    pic2.src="image2.gif";
    pic3= new Image(pic_width,pic_height);
    pic3.src="image3.gif";
    pic4= new Image(pic_width,pic_height);
    pic4.src="image4.gif";
    pic5= new Image(pic_width,pic_height);
    pic5.src="image5.gif";
    }

    /* define banner urls */

    urlad1="http://www.someplace.com";
    urlad2="http://www.someplace.com";
    urlad3="http://www.someplace.com";
    urlad4="http://www.someplace.com";
    urlad5="http://www.someplace.com";

  4. Check the Format Window to be sure you do not have one single line of code, or too many line breaks in the code.

Example

A working sample of the script is shown below.

JavaScript Book
JavaScript: A Beginner's Guide
by John Pollock
What's New
Simple Searchbox script added.
More...
Web Xpertz
Find more JavaScript tools and resources at WebXpertz City! Click one of the links above to browse the various attractions within the city.