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

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


Skwolven

Question

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 post
  • Answers 2
  • Created
  • Last Reply

Top Posters For This Question

Popular Days

Top Posters For This Question

Popular Posts

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.

2 answers to this question

Recommended Posts

Create an account or sign in to comment

You need to be a member in order to leave a comment


×
×
  • Create New...