Open a link on the same tab

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
    }
});

Hello Shirley,

perhaps this way. Just a theoretical thought. Did not test it.

import wixWindow from 'wix-window';
import wixData from 'wix-data';

$w.onReady(async function () {

 
 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
        items[rnd[0]].target = 'self';
        }, {
 "type": "image",
 "alt": items[rnd[1]].title,
 "title": items[rnd[1]].title,
 "src": items[rnd[1]].image,
 "link": items[rnd[1]].link
        items[rnd[1]].target = 'self';
        }, {
 "type": "image",
 "alt": items[rnd[2]].title,
 "title": items[rnd[2]].title,
 "src": items[rnd[2]].image,
 "link": items[rnd[2]].link
        items[rnd[2]].target = 'self';
        }];
 
        $w('#gallery1').show(); // show the gallery after the images are set
    }
});

Hi R ussian- Dima , thank you very much for your help but it didn’t work. No pic wash shown on the page and there was an error message " Parsing error: Unexpected token items ". Please let me know if there is any way to fix it. Thank you so much!

I will have to reconstruct it, to find the ERROR or a SOLUTION.
So if there is anybody whon can help the next time, i will take a look at this.

But i hope there will be somebody who can do it on the fly.

Thank you! Please do let me kow if you find a solution.