Results 1 to 7 of 7

Thread: HTML: Code for alternating images on page load

  1. #1
    Join Date
    Jul 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default HTML: Code for alternating images on page load

    Hi all, Ive been surfing the forum all day. All I can see is some code for an array.

    What do I need to do in Frontpage to get a new image (which is hyperlinked) to load everytime the page loads.

    In other words everytime the page is opened you get a whole new clickable image - an alternating image something along the lines of the way some ad services work.

    Is the array the best way? because I couldnt get that code to work no matter what i did, and didnt even get as far as figureing out the hyperlinks for each picture would figure into that.

    Please help - I feel like an idiot (and not just for having to do this in Frontpage - work thing - don't ask )

    Thanks

  2. #2
    Join Date
    Jul 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    You can try js or php.

  3. #3
    Join Date
    Feb 2007
    Posts
    293
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    A javascript array will generate a clickable picture. Put this where you want the images to appear.

    Code:
    <script type="text/javascript">
    var piclink = new Array(4);
    piclink[0] = "<a href = 'http://www.link1.htm'><img src='pic1.gif' alt='whatever' style='border:0'></a>";
    piclink[1] = "<a href = 'http://www.link2.htm'><img src='pic2.gif' alt='whatever' style='border:0'></a>";
    piclink[2] = "<a href = 'http://www.link3.htm'><img src='pic3.gif' alt='whatever' style='border:0'></a>";
    piclink[3] = "<a href = 'http://www.link4.htm'><img src='pic4.gif' alt='whatever' style='border:0'></a>";
    
    index  = Math.floor(Math.random() * piclink.length);
    document.write(piclink[index]);
    
    </script>
    You can add as many as you want. Just give them the number that's next in sequence, eg if you want to add one more image make it piclink[4] And you will also need to change the number in new Array(4) to whatever your total is, eg for one more image it will be new Array(5).

    If you have to use Frontpage, you should do this in View Source HTML mode. Just copy and paste

  4. #4
    Join Date
    Jul 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default works great but...

    would anyone know why this code won't work with multiple instances of it per page? in other words...when I have two sets of that code in place one might come up and then the other image doesnt come up at all and says "undefined" in the spot i placed it in...

    thanks!

  5. #5
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    You have to copy that block and replace "piclink" with a new name in the copied block.
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

  6. #6
    Join Date
    Jul 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default still does not seem to be working

    i tried fixing that problem...does anyone know why it still might not be working? blarg.

  7. #7
    Join Date
    Mar 2007
    Posts
    66
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default load on page load

    your mt try the script here:

    http://www.dynamicdrive.com/forums/s...function+robin

    I used it on my site http://www.frankconnet.com

    a new image loads on each page load. I think I have about 12 but it would work the same way with two.

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
  •