Jump to content

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

Recommended Posts

Posted

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>

 

  • Replies 2
  • Views 802
  • Created
  • Last Reply
Posted

OK, I fixed it by turning of Ajax loading, but if someone knows how to rewrite the script so it would work with Ajax enabled I'd be super appreciative!

Posted

Hi @Skwolven,

Ajax loading can often affect the function of custom code, as mentioned here. It may not be possible to implement any code on these pages of your site while Ajax loading is enabled.

Hope that helps!

cg1q_g5kO_xGfCuu4Be7izVV_NRhqDc4ve0tGQPjM9KcJEsGk7_r2aOC3TvFDREPcEBeqkVyVYkbcd2f5SqEBwjMR67QYD2Kew-OhW65fVNWvTGdP1cmXHWUSbycirsSKTcnHL_G
SPENCER CHRISTIE
CUSTOMER OPERATIONS ADVISOR
HE/HIM

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.