Jump to content

Why is my random background image not working now that my site is live?

Recommended Posts

Site URL: https://fredfilms.com

I have a custom script on my homepage that loads a different background image each time the page loads. It works great when I view my website within the squarespace editor, but now that the site is live it is doing something weird. I checked in multiple browsers and it's consistently having this same problem.

When I refresh my browser it works great! The trouble is that if I navigate to the home page with any of the nav links or the logo in the main nav then I just get a grey background with no image. Any insights into this issue would be GREATLY appreciated. (I have more images than this in the actual page, but for brevity's sake I took most of them out here)

<script type="text/javascript">
 var images = /*//add image urls here in single quotes, the order does not matter//*/ ['https://static1.squarespace.com/static/5f32e3f1b490445685cb1d10/5f67c7c9ef095d17b781a722/5f67c7d40587154ff889354b/1600636891257/AdventureTime.jpg', 
 /*//this part chooses the image from the urls above//*/ 
	document.getElementById("title").style.backgroundImage = 'url(" ' + images[Math.floor(Math.random() * images.length)] + '")';


Link to comment
  • Replies 2
  • Views 739
  • Created
  • Last Reply


This topic is now archived and is 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.