Jump to content

Display random image on page

Recommended Posts

  • 5 months later...
  • Replies 6
  • Created
  • Last Reply

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

Link to comment

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

Link to comment
  • 3 months later...
  • 2 weeks later...

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.

Link to comment
  • 1 year later...

Archived

This topic is now archived and is closed to further replies.

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.