Page 1 of 1

Random Image JavaScript source code

Posted: Wed Oct 26, 2011 3:57 pm
by Nipuna
Today for a freelancer work of mine. I wanted a random image script. Then I found this and tested and working very well.

So I thought to share with all ROBOT.LK members.

Code: Select all

<script type="text/javascript">

function random_imglink(){

var myimages=new Array()

//specify random images below. You can have as many as you wish
myimages[1]="https://robot.lk/test1.jpg"
myimages[2]="https://robot.lk/test2.jpg"
myimages[3]="https://robot.lk/test3.jpg"
myimages[4]="https://robot.lk/test4.jpg"

var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<img src="'+myimages[ry]+'" border=0></a>')
}

random_imglink()
</script>