Hi, I’m trying to make the splash page on my website randomise an image from a dataset that I’ve set up. It works perfectly in preview mode when I’m still in the site editor, but once I’ve published the site and I go to check the live site, the splash page seems to even load in any images, nevermind randomise them. Here is my source code for the page in question:
import wixWindow from ‘wix-window’ ;
import wixData from ‘wix-data’ ;
$w.onReady( async function () {
// Check the render env so this is just done once.
// Otherwise, server-side will render, and then the image
// switches to the image that the client-side rendered.
if (wixWindow.rendering.env === ‘browser’ || wixWindow.viewMode === ‘preview’ ) {
let res = await wixData.query( “SplashPageDataset” ).find();
let items = res.items;
let count = items.length; // how many images do we have?
let rnd = Math.floor(Math.random() * count);
$w( “Document” ).background.src = items[rnd].image; // get a random image
$w( ‘#columnStrip8’ ).show(); // image on page is hidden, we we now show it
}
});
It’s frustrating that it won’t work on the live site, but it seems like it’s something simple that I’m overlooking. Can anybody give me some advice?