Posted By

Jaymoon on 08/11/06


Tagged

javascript image link html random


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

guerrera
vali29


Random image with link


 / Published in: JavaScript
 

The ideal use of this code would be to save the Javascript code as a .js file. Then use the HTML code at the bottom to call it wherever you want on the web page.

  1. <!-- Javascript code begins -->
  2.  
  3. var randomlinks=new Array()
  4.  
  5. randomlinks[0]='<img alt="" src="images/image-01.gif" width="150" height="75">'
  6. randomlinks[1]='<img alt="" src="images/image-02.gif" width="150" height="75">'
  7. randomlinks[2]='<img alt="" src="images/image-03.gif" width="150" height="75">'
  8.  
  9. function randomlink(){
  10. var add = randomlinks[Math.floor(Math.random()*randomlinks.length)]
  11. return(add)
  12. }
  13.  
  14. document.write( randomlink() );
  15.  
  16. <!-- Javascript code ends -->
  17.  
  18.  
  19.  
  20. <!-- HTML code to use script -->
  21.  
  22. <script type="text/javascript" src="path/to/script.js"></script>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: rileycentral on October 23, 2008

How and where do you add the links? Thanks.

You need to login to post a comment.