Rotating Advertisement Banners



The image above is being rotated between three different graphics. Clicking on a banner will send you to the banner's corresponding sponsor. (For this example, clicking will simply display a message in a dialog.)

 

  • Source

    <HTML>
    <HEAD>
    <TITLE>Rotating Advertisements</TITLE>
    </HEAD>
    <SCRIPT LANGUAGE="JavaScript">
    // global variable for current sponsor
    var sponsor = 1;
    
    // function to link to appropriate sponsor
    // (for demonstration, displays a dialog instead)
    function GoSponsor() {
       window.alert("Sponsor number to link to:" + sponsor);
    }
    
    // function to rotate image (currently uses 3 images)
    function rotate() {
       if (++sponsor > 3)  sponsor = 1;
       document.images[0].src = "banner" + sponsor + ".gif";
       window.setTimeout('rotate();',5000);
    }
    </SCRIPT>
    <BODY onLoad="window.setTimeout('rotate();',5000);">
    <h1>Rotating Advertisement Banners</h1>
    <hr>
    <A HREF="javascript:GoSponsor();">
    <IMG NAME="banner" SRC="banner1.gif">
    </A>
    <hr>
    The image above is being rotated between three different graphics. Clicking
    on a banner will send you to the banner's corresponding sponsor. (For this
    example, clicking will simply display a message in a dialog.)
    <hr>
    
    </BODY>
    </HTML>