Results 1 to 5 of 5

Thread: How to create a randomly selected banner?

  1. #1
    Join Date
    Sep 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to create a randomly selected banner?

    I´ve started a forum at invisionfree.com and would like to have a randomly selected image displayed at the top of the page each time you load/reload the page. I´ve tried using various online tutorials without success, and now I´ve been recommended to use this place. So could you write the code I need to use, and leave a "blank" in the areas I need to fill in with image locations? I´m a computer iliterate, so I need things spelled out for me. Thanks in advance.

  2. #2
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    Hope this basic example helps:
    HTML Code:
    <style type="text/css">
    .myimage{width:400px;height:300px;}
    </style>
    <script type="text/javascript">
    /*
    * Title: Random Image Script
    * Code by Raymond Angana. username: rangana [dynamicdrive.com/forums]
    * This notice must remain intact
    */
    var rPics=[
    'http://rangana.moonylist.com/images/Picture7.jpg',
    'http://rangana.moonylist.com/images/Picture2.jpg',
    'http://rangana.moonylist.com/images/Picture3.jpg',
    'http://rangana.moonylist.com/images/Picture4.jpg' // note that the last element in the array dont have comma
    ]; // Add all the picture variables in this array.
    
    window.onload=function() {
    rRandom=Math.floor(Math.random()*rPics.length); // Randomly choose a number
    var img=document.createElement('img'); // Create an image element
    img.setAttribute('src',rPics[rRandom]); // Set the source of the image
    img.className='myimage'; // Set a class name for the image. This is use to style the image via CSS
    document.getElementById('header').appendChild(img); // Append the image
    }
    </script>
    <div id="header">
    <h1>Banner Here</h1>
    </div>
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  3. #3
    Join Date
    Sep 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Well, the image shows now, but underneath the preceding banner (there´s already a banner on the site which will be a regular image displayed), is there a way to have the randomly selected image show next to the banner? And the images that get randomly selected get stretched/shrinked, is there a way to remove the automatic resizing?

  4. #4
    Join Date
    Sep 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    And as long as I´m being difficult; the banner and image are displayed against a background made up of horizontal blue stripes which I really don´t like, is there a way to make the background area all white?

  5. #5
    Join Date
    Feb 2008
    Posts
    9
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Openx

    Openx is free software for displaying ads. You will need access to mysql to create a database. After you get the program installed displaying ads will be simple....... No more messing with scripts. It will work to rotate or display images, ads, html blocks, flash. Goolge it you will like what you see!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •