# How to make "Field Type 'URL'" from database open in same window

**URL:** <https://forum.wixstudio.com/t/how-to-make-field-type-url-from-database-open-in-same-window/31042>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [October 20, 2020, 7:42am UTC](https://forum.wixstudio.com/t/how-to-make-field-type-url-from-database-open-in-same-window/31042 "2020-10-20T07:42:28Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![tali54657](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/tali54657/32/15935_2.png) [@tali54657](https://forum.wixstudio.com/u/tali54657)\
**Post date:** [October 20, 2020, 7:42am UTC](https://forum.wixstudio.com/t/how-to-make-field-type-url-from-database-open-in-same-window/31042/1 "2020-10-20T07:42:28Z")

</div>

I have dynamic pages and one of the buttons is linked to the “URL” field type of my database collection. The link works fine from the dynamic page only it opens in a new window. Is there any way to make it open in the same window?

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [October 20, 2020, 7:49am UTC](https://forum.wixstudio.com/t/how-to-make-field-type-url-from-database-open-in-same-window/31042/2 "2020-10-20T07:49:41Z")

</div>

You can use the [target](https://www.wix.com/corvid/reference/$w/button/target) property of the Button to set the link’s behavior.

---

<div class="post-metadata">

**Author:** ![tali54657](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/tali54657/32/15935_2.png) [@tali54657](https://forum.wixstudio.com/u/tali54657)\
**Post date:** [October 20, 2020, 8:02am UTC](https://forum.wixstudio.com/t/how-to-make-field-type-url-from-database-open-in-same-window/31042/3 "2020-10-20T08:02:08Z")

</div>

Hi Yisrael,

Thanks, but because the button links to a URL in my database collection there is no option to change the button’s properties:

 ![](https://us1.discourse-cdn.com/wix/original/3X/7/f/7fc3d0c9ec30041abc3e9d2d5c815757eef9fd3a.jpeg)

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [October 20, 2020, 8:05am UTC](https://forum.wixstudio.com/t/how-to-make-field-type-url-from-database-open-in-same-window/31042/4 "2020-10-20T08:05:19Z")

</div>

@tali54657 As shown in the link that I provided, the [target](https://www.wix.com/corvid/reference/$w/button/target) property is set in code:

```javascript
$w("#myButton").target = "_self";

```

---

<div class="post-metadata">

**Author:** ![tali54657](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/tali54657/32/15935_2.png) [@tali54657](https://forum.wixstudio.com/u/tali54657)\
**Post date:** [October 20, 2020, 8:15am UTC](https://forum.wixstudio.com/t/how-to-make-field-type-url-from-database-open-in-same-window/31042/5 "2020-10-20T08:15:07Z")

</div>

@yisrael-wix thanks but it doesn’t work…

---

<div class="post-metadata">

**Author:** ![tali54657](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/tali54657/32/15935_2.png) [@tali54657](https://forum.wixstudio.com/u/tali54657)\
**Post date:** [October 20, 2020, 8:16am UTC](https://forum.wixstudio.com/t/how-to-make-field-type-url-from-database-open-in-same-window/31042/6 "2020-10-20T08:16:25Z")

</div>

```javascript

$w("#button1").link = "https://tali377.wixsite.com/noravnew/resting-ecg/mobile-app";
$w("#button1").target = "_self";

```

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [October 20, 2020, 8:31am UTC](https://forum.wixstudio.com/t/how-to-make-field-type-url-from-database-open-in-same-window/31042/7 "2020-10-20T08:31:43Z")

</div>

@tali54657 You need to put that code in the page’s [onReady()](https://www.wix.com/corvid/reference/$w/onready) function. It won’t work otherwise.

```javascript
$w.onReady( function() {
   $w("#button1").link = "https://tali377.wixsite.com/noravnew/resting-ecg/mobile-app";
   $w("#button1").target = "_self";
} );

```

---

<div class="post-metadata">

**Author:** ![tali54657](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/tali54657/32/15935_2.png) [@tali54657](https://forum.wixstudio.com/u/tali54657)\
**Post date:** [October 20, 2020, 8:40am UTC](https://forum.wixstudio.com/t/how-to-make-field-type-url-from-database-open-in-same-window/31042/8 "2020-10-20T08:40:27Z")

</div>

@yisrael-wix yes I had it with the onReady() command, I was missing a semicolon and a closing “)”…it works now! Thank you so much for the help!!! 🙂

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [October 20, 2020, 8:44am UTC](https://forum.wixstudio.com/t/how-to-make-field-type-url-from-database-open-in-same-window/31042/9 "2020-10-20T08:44:57Z")

</div>

@tali54657 Also, you really only need to set the target property in the onReady. The link property can be set elsewhere in code, according to results from queries or other logic you might have.

---

<div class="post-metadata">

**Author:** ![williamatreus](https://avatars.discourse-cdn.com/v4/letter/w/b9e5f3/32.png) [@williamatreus](https://forum.wixstudio.com/u/williamatreus)\
**Post date:** [January 17, 2024, 12:01am UTC](https://forum.wixstudio.com/t/how-to-make-field-type-url-from-database-open-in-same-window/31042/10 "2024-01-17T00:01:30Z")

</div>

I’d like to do this but instead of a link opening from a button it opens from an image in a gallery.  
Do i replace the “#mybutton” with the link field i.d?
