Random Image JavaScript source code

Web hosting, SEO, etc... related

Random Image JavaScript source code

Postby Nipuna » Wed Oct 26, 2011 10:27 am

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 EC members.

Syntax: [ Download ] [ Hide ]
Using Javascript Syntax Highlighting
  1. <script type="text/javascript">
  2.  
  3. function random_imglink(){
  4.  
  5. var myimages=new Array()
  6.  
  7. //specify random images below. You can have as many as you wish
  8. myimages[1]="http://www.expertcore.org/test1.jpg"
  9. myimages[2]="http://www.expertcore.org/test2.jpg"
  10. myimages[3]="http://www.expertcore.org/test3.jpg"
  11. myimages[4]="http://www.expertcore.org/test4.jpg"
  12.  
  13. var ry=Math.floor(Math.random()*myimages.length)
  14. if (ry==0)
  15. ry=1
  16. document.write('<img src="'+myimages[ry]+'" border=0></a>')
  17. }
  18.  
  19. random_imglink()
  20. </script>
  21.  
Syntax parsed in 0.003 seconds
User avatar
Nipuna
Promo Team
Promo Team
 
Posts: 2637
Joined: Mon Jan 04, 2010 2:32 pm
Cash on hand: 31,325.60
Bank: 470,602.10
Location: Deraniyagala,SRI LANKA
Medals: 2
EC_Bronze_Star (1) EC_Achievment (1)

Invitations sent: 5
Registered friends: 0
Highscores: 1
Reputation point: 33
Staff Sergeant

Return to Web Related

Who is online

Users browsing this forum: No registered users and 1 guest