Opening database link in same window

I am working on a site where I have created a database to handle a user dashboard. I have a button link on my dashboard, which links to a URL field in the database (it links to a page on my site specific to that user). I have it working, but when I click on the button, it opens the page in a new window. How can I get the button to use the database URL but open the the page in the same window. I found this code in another post, but I must not be calling it properly on my click:

import wixLocation from ‘wix-location’;
export function button1_click_1($w) {
let link = $w(“#button1”).link;
console.log(link);
wixLocation.to(link);
}

Where am I going wrong here?

Thanks–

Al

2 Likes

Following. I came in search to resolve the same issue.

got it - just added one line to page code

your code woud be $w("#button1").target = "_self";

Hi gaspar.al did you manage to solve the problem? If so would you be so kind as to explain how you did it?

Thanks in advance!

I am using this as code.

import wixLocation from ‘wix-location’;
export function image1_click_1($w) {
let link = $w(“#image1”).link;
console.log(link);
wixLocation.to(link);
}
$w(“#image1”).target = “_self”;

Im not getting anything in the console which is strange.

Also its not working. When you hover over it you can see the link, and if you right click and say open in new tab it opens. But clicking does nothing.

changed the $w to $item and that worked. It was in a repeater

Hey guys, I just set the link of the button to a page in the site and clicked open in the same window. Now it works. No code needed!

but then that link doesnt change based on the database values, does it?