# Opening database link in same window

**URL:** <https://forum.wixstudio.com/t/opening-database-link-in-same-window/28839>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [February 25, 2018, 3:27am UTC](https://forum.wixstudio.com/t/opening-database-link-in-same-window/28839 "2018-02-25T03:27:39Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![gaspar-al](https://avatars.discourse-cdn.com/v4/letter/g/cdc98d/32.png) [@gaspar-al](https://forum.wixstudio.com/u/gaspar-al)\
**Post date:** [February 25, 2018, 3:27am UTC](https://forum.wixstudio.com/t/opening-database-link-in-same-window/28839/1 "2018-02-25T03:27:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![doug-hoag](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/doug-hoag/32/3572_2.png) [@doug-hoag](https://forum.wixstudio.com/u/doug-hoag)\
**Post date:** [May 4, 2018, 3:29am UTC](https://forum.wixstudio.com/t/opening-database-link-in-same-window/28839/2 "2018-05-04T03:29:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![doug-hoag](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/doug-hoag/32/3572_2.png) [@doug-hoag](https://forum.wixstudio.com/u/doug-hoag)\
**Post date:** [May 4, 2018, 4:04am UTC](https://forum.wixstudio.com/t/opening-database-link-in-same-window/28839/3 "2018-05-04T04:04:58Z")

</div>

got it - just added one line to page code

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

```

---

<div class="post-metadata">

**Author:** ![leopoldtaylor](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/leopoldtaylor/32/6917_2.png) [@leopoldtaylor](https://forum.wixstudio.com/u/leopoldtaylor)\
**Post date:** [November 27, 2018, 4:18pm UTC](https://forum.wixstudio.com/t/opening-database-link-in-same-window/28839/4 "2018-11-27T16:18:25Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![joey35854](https://avatars.discourse-cdn.com/v4/letter/j/c6cbf5/32.png) [@joey35854](https://forum.wixstudio.com/u/joey35854)\
**Post date:** [September 18, 2020, 4:27am UTC](https://forum.wixstudio.com/t/opening-database-link-in-same-window/28839/5 "2020-09-18T04:27:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![joey35854](https://avatars.discourse-cdn.com/v4/letter/j/c6cbf5/32.png) [@joey35854](https://forum.wixstudio.com/u/joey35854)\
**Post date:** [September 18, 2020, 4:58am UTC](https://forum.wixstudio.com/t/opening-database-link-in-same-window/28839/6 "2020-09-18T04:58:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![simone](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/simone/32/706_2.png) [@simone](https://forum.wixstudio.com/u/simone)\
**Post date:** [March 20, 2022, 1:37am UTC](https://forum.wixstudio.com/t/opening-database-link-in-same-window/28839/7 "2022-03-20T01:37:40Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![guinsqnsq](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/guinsqnsq/32/34280_2.png) [@guinsqnsq](https://forum.wixstudio.com/u/guinsqnsq)\
**Post date:** [August 3, 2022, 2:29pm UTC](https://forum.wixstudio.com/t/opening-database-link-in-same-window/28839/8 "2022-08-03T14:29:41Z")

</div>

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