Forum Moderators: open

Message Too Old, No Replies

dynamicall generated images

different image displayed each time the page is refreshed

         

contentmaster

8:10 am on Feb 12, 2004 (gmt 0)

10+ Year Member



Hi
I was wondering if some one could help me .....this is what i want to achieve :I am using fp to create my webpages

I have a couple of images something like a banner .....each focussing on some important aspects that i want to project through my site... i want to find out a way by which a different image is displayed each time the page is refreshed....in other words..the images (banner) should dynamically change on the webpage.... can this be done and how!?

isitreal

5:45 pm on Feb 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



This thread would answer most questions:

[webmasterworld.com...]

you just have to change a few things in the code, instead of using document.getElementById() on the id of the thing, you'd just asign the array value to a variable and then use document.write to write the image tag using that variable as the url, make sure to include a <noscript>image</noscript> so the page can default to something if no javascript.

example:
<html>
<head>
<title></title>
<script type="text/javascript">
function random_image()
{
image_array = new Array();
image_array[0] = '/images/image02.jpg';
image_array[1] = '/images/image03.jpg';
image_array[2] = '/images/image04.jpg';

count = image_array.length;
random = Math.floor(Math.random() * count);

document.write( "<img src=\"" + image_array[random] + "\">");
}
</script>
</head>
<body>
<script>random_image()</script>
</body>
</html>