Hi, I used a link here ( https://www.wix.com/corvid/forum/community-discussion/random-slideshow ) to let pictures randomly picked from the database and shown on the page.
I added a few lines so clicking the picture will open a link on a new tab/window. But I want the link open only on the same tab instead of a new one.
I have been trying different codes since last week but still not working. I tried this link ( https://www.wix.com/corvid/forum/community-discussion/repeater-open-link-in-same-window ) but couldn’t get the code right…
Does anyone know how to fix this? Thank you sooooo much in advance! Below is my code.
// For full API documentation, including code examples, visit http://wix.to/94BuAAs
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 gallery images
// switch to the gallery images that the client-side rendered.
if (wixWindow.rendering.env === 'browser' || wixWindow.viewMode === 'Preview') {
let res = await wixData.query("HomepageImages").find();
let items = res.items;
let count = items.length; // how many images do we have?
let link = items.link;// link.
const size = 3; // # of images to display in the gallery
var rnd = [];
while (rnd.length < size) {
var r = Math.floor(Math.random() * count);
if (rnd.indexOf(r) === -1) rnd.push(r);
}
$w("#gallery1").items = [{
"type": "image",
"alt": items[rnd[0]].title,
"title": items[rnd[0]].title,
"src": items[rnd[0]].image,
"link": items[rnd[0]].link
}, {
"type": "image",
"alt": items[rnd[1]].title,
"title": items[rnd[1]].title,
"src": items[rnd[1]].image,
"link": items[rnd[1]].link
}, {
"type": "image",
"alt": items[rnd[2]].title,
"title": items[rnd[2]].title,
"src": items[rnd[2]].image,
"link": items[rnd[2]].link
}];
$w('#gallery1').show(); // show the gallery after the images are set
}
});