Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Advanced Search
  • 1
mwintner1

Display random image on page

Question

6 answers to this question

Recommended Posts

  • 2

Yeah it took forever to figure out, especially since I have basically zero JS/HTML knowledge. Happy to share though:

Make an unlinked page and make it your home page.Add a code block and paste this:


<script language="JavaScript">
<!--

function random_imglink(){
var myimages=new Array()
//specify random images below. You can have as many as you wish
myimages[1]="http://whatever.com/picture.jpg"
myimages[2]="http://whatever.com/image.jpg"
myimages[3]="http://whatever.com/graphic.jpg"

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


Make sure that for every image you add you update the number next to myimages[x]. The whatever.com URLs are the direct URLs of whatever image you're using. All the URLs I used were from pictures I'd already uploaded on other parts of my squarespace site.

Share this post


Link to post
  • 1
Guest

Hi, I saw you've managed to get this working on your site. Great stuff!Would it be possible to let me know how it's done?I've been trying for ages with no joy.

Many thanksCharlotte

Share this post


Link to post
  • 0
Guest

Hi, I saw you've managed to get this working on your site. Great stuff!Would it be possible to let me know how it's done?I've been trying for ages with no joy.

Many thanksCharlotte

Share this post


Link to post
Guest
This topic is now closed to further replies.

×
×
  • Create New...