Random Image JavaScript source code

Web hosting, SEO, etc... related
Post Reply
User avatar
Nipuna
Moderator
Moderator
Posts: 2729
Joined: Mon Jan 04, 2010 8:02 pm
Location: Deraniyagala,SRI LANKA

Random Image JavaScript source code

Post by Nipuna » Wed Oct 26, 2011 3:57 pm

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>
Post Reply

Return to “Web Related”