View Full Version : HTML: Code for alternating images on page load

07-24-2007, 08:27 PM
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 :) )


07-26-2007, 05:16 PM
You can try js or php.

07-26-2007, 11:54 PM
A javascript array will generate a clickable picture. Put this where you want the images to appear.

<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);


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

08-09-2007, 08:34 PM
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...


08-09-2007, 11:15 PM
You have to copy that block and replace "piclink" with a new name in the copied block.

08-16-2007, 01:41 AM
i tried fixing that problem...does anyone know why it still might not be working? blarg.

08-16-2007, 10:28 PM
your mt try the script here:


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.