I want set of embed link to be displayed. There should be a space where the content of embed link is displayed. And if the user refreshes the page, then the embed link changes every time. I did research in the forum, but was able to find code for random pic homepage which is:
import wixWindow from 'wix-window';
import wixData from 'wix-data';
$w.onReady(async function () {
// Check the render cycle 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.renderCycle === 1) {
let res = await wixData.query("AdvertisementImage").find();
let items = res.items;
let count = items.length; // how many images do we have?
let rnd = Math.floor(Math.random() * count);
$w('#adimage').src = items[rnd].image; // get a random image
}
});
Update:
I am using the following code after editing the above code to suit me but it is still not working:
import wixWindow from 'wix-window';
import wixData from 'wix-data';
$w.onReady(async function () {
// Check the render cycle so this is just done once.
// Otherwise, server-side will render, and then the link
// switches to the link that the client-side rendered.
if (wixWindow.rendering.isNotEmpty('Quiz') === 1) {
let res = await wixData.query("Quiz").find();
let items = res.items;
let count = items.length; // how many links do we have?
let rnd = Math.floor(Math.random() * count);
$w('#html1').src = items[rnd].url; // get a random link
}
});
Help please