# Javascript for the URL field to open in same window

**URL:** <https://forum.wixstudio.com/t/javascript-for-the-url-field-to-open-in-same-window/12395>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [December 10, 2017, 5:21am UTC](https://forum.wixstudio.com/t/javascript-for-the-url-field-to-open-in-same-window/12395 "2017-12-10T05:21:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![horngwey](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/horngwey/32/82418_2.png) [@horngwey](https://forum.wixstudio.com/u/horngwey)\
**Post date:** [December 10, 2017, 5:21am UTC](https://forum.wixstudio.com/t/javascript-for-the-url-field-to-open-in-same-window/12395/1 "2017-12-10T05:21:39Z")

</div>

Currently, the URL field in the dataset only opens in a new window when you assigned it to text, image or button site elements. I will need it to open in the same window. How do I write a JS for this function and hook it to the dataset? Is this the right way to do it?

---

<div class="post-metadata">

**Author:** ![\_tal](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/_tal/32/669_2.png) [@\_tal](https://forum.wixstudio.com/u/_tal)\
**Post date:** [December 10, 2017, 12:53pm UTC](https://forum.wixstudio.com/t/javascript-for-the-url-field-to-open-in-same-window/12395/2 "2017-12-10T12:53:58Z")

</div>

Hi,  
You can create an [onClick](https://www.wix.com/code/reference/$w.Button.html#onClick) event to the relevant element ( image, text, button etc…) and use the to( ) function of the [Wix-Location API](https://www.wix.com/code/reference/wix-location.html#to) to redirect to the relevant URL.

Good luck,  
Tal

---

<div class="post-metadata">

**Author:** ![robinengelbach](https://avatars.discourse-cdn.com/v4/letter/r/7cd45c/32.png) [@robinengelbach](https://forum.wixstudio.com/u/robinengelbach)\
**Post date:** [June 9, 2020, 8:38am UTC](https://forum.wixstudio.com/t/javascript-for-the-url-field-to-open-in-same-window/12395/3 "2020-06-09T08:38:52Z")

</div>

Did someone find a solution for this to connect an url with .target = “\_self” without including an image, text, button etc ?
