Random Image on Page Javascript
This little bit of code will allow you to revolve several images on a web page each time the page reloads. Just update your image location between the "" for each myimages variable and the corresponding link between the "" for each imagelinks variable. Add more if you like or take some away.
<script language="JavaScript"> <!-- function random_imglink(){ //specify random images below. You can have as many as you wish var myimages=new Array() myimages[1]="images/image.png" myimages[2]="images/image.png" myimages[3]="images/image.png" myimages[4]="images/image.png" myimages[5]="images/image.png" //specify corresponding links below var imagelinks=new Array() imagelinks[1]="http://website.com/index.php" imagelinks[2]="http://website.com/index.php" imagelinks[3]="http://website.com/index.php" imagelinks[4]="http://website.com/index.php" imagelinks[5]="http://website.com/index.php" var ry=Math.floor(Math.random()*myimages.length) if (ry==0) ry=1 document.write('<a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" border=0></a>') } random_imglink() //--> </script>



Leave a Reply