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', 
               'https://static1.squarespace.com/static/5f32e3f1b490445685cb1d10/5f67c7c9ef095d17b781a722/5f67c7d4c9621301a2132b00/1600636888637/Bravest-Warriors-900x506.jpg', 
              'https://static1.squarespace.com/static/5f32e3f1b490445685cb1d10/5f67c7c9ef095d17b781a722/5f67c7dd84df667bd7f43922/1600636898493/castlevania3.jpg',
                                                                                       'https://static1.squarespace.com/static/5f32e3f1b490445685cb1d10/5f67c7c9ef095d17b781a722/5f90d3398363457e25a089be/1603326782909/Adventure+Time+4.jpg'];
  
 /*//this part chooses the image from the urls above//*/ 
	document.getElementById("title").style.backgroundImage = 'url(" ' + images[Math.floor(Math.random() * images.length)] + '")';
</script>

 

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

Archived

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.