+ Reply to Thread
Results 1 to 4 of 4

Thread: Javascript banner rotation

  1. #1
    BlueDevil is offline x10Hosting Member BlueDevil is an unknown quantity at this point
    Join Date
    May 2008
    Posts
    5

    Javascript banner rotation

    Javascript banner rotation

    This tutorial will teach you how to create a code that makes a random image link appear each time you refresh a page. This is ideal for ad banners.

    Step one

    Create a file in a text editor(e.g. notepad) and save it as advert.js. This is the javascript file you will be using.
    Then put in this code:
    Code:
    //this creates a new array called banners
    banners = new Array();
    
    //this sets strings to the values in the array
    //the markup is like this: "Website url,Banner url,Site description,Banner Width,Banner Height"
    banners[0] = "http://www.site.com,banner.gif,Description,468,60";
    banners[1] = "http://www.site2.com,banner2.gif,Description2,200,100";
    banners[2] = "http://www.site3.com,banner3.gif,Description3,700,200";
    
    //this create a random number between 0 and the length of the array(2 in this case)
    rand = Math.floor(Math.random() * banners.length);
    //this splits the string in the array into the strings that were separated by commas and calls it b.
    b = banners[rand].split(",");
    
    //this creates variable for the new strings that were split from the banners array
    url = b[0];
    img = b[1];
    des = b[2];
    wid = b[3];
    hei = b[4];
    
    //this is the html markup that will display the banner on your site
    document.write('<a href="' + url + '" target="_blank"><img src="' + img + '" width="'+ wid +'" height="'+ hei +'" border="0" alt="' + des + '" /></a>');
    Step two

    Open up your html file and put this code where you want your banner to be:
    Code:
    <script src="advert.js" type="text/javascript"></script>
    Upload the file onto your server and you're done

  2. #2
    YCadmin is offline x10Hosting Member YCadmin is an unknown quantity at this point
    Join Date
    Aug 2008
    Posts
    56

    Re: Javascript banner rotation

    Thanks for the tutorial! It makes my site looks better!


  3. #3
    tittat's Avatar
    tittat is offline x10 Spammer tittat is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Kerala,India
    Posts
    2,479

    Re: Javascript banner rotation

    A simple tutorial, but really helpful.
    thanks BlueDevil....
    PLAY ONLINE GAMES
    WWW.TMONDO.COM PlayFar Flash Games
    Former X10 Forum Senior Moderator(Retired)


  4. #4
    sunils's Avatar
    sunils is offline x10 Spammer sunils is an unknown quantity at this point
    Join Date
    Jan 2008
    Location
    Chennai ,India
    Posts
    2,264

    Re: Javascript banner rotation

    Good one for a basic ad rotator.
    [LEFT][B]Sunil Sankar
    -------------------------------------------------------------------------

+ Reply to Thread

Similar Threads

  1. x10Hosting Ads as a Banner in Joomla!
    By s906201 in forum Tutorials
    Replies: 10
    Last Post: 08-26-2008, 07:07 PM
  2. Simple Banner Rotator
    By cellporn in forum Tutorials
    Replies: 2
    Last Post: 05-12-2008, 02:11 PM
  3. Banner rotation - Using what? and how?
    By Lord Of The Land in forum Scripts & 3rd Party Apps
    Replies: 10
    Last Post: 03-18-2008, 12:08 PM
  4. Seas2Success - Custom Banner Offer!
    By loveboat in forum Ads & Offers
    Replies: 9
    Last Post: 02-08-2008, 11:34 PM
  5. XML and Javascript
    By cuteboytm in forum Graphics & Webdesign
    Replies: 1
    Last Post: 09-21-2007, 10:00 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers