how can I open a new tab from a repeater button?

Hi,
I have a repeater that shows info from a dataset,
and I connected everything OK.
I build a URL using the info from the dataset, but I can’t get it to open in a new tab.
I tried to define the element’s link in the “OnReady” section,
and tried it on “OnClick” button.
I also know about “target = _blank” but no success.

Here is the “onReady” code:

$w.onReady(() => {
    $w("#dataset1").onReady( () => {
        $w("#repeaterRent").onItemReady(($item, itemData, index) => {
                   // open google maps in a new tab
                   let mapsURL = "https://someWebsite"
                   + $item("#buttonAddress").label.toString().rep(" ", "+")
                   + "," + $item('#textCity').text.replace(" ", "+");
                   //console.log(mapsURL);
                   $item("#buttonAddress").link = mapsURL;
                   $item("#buttonAddress").target = "_blank";
        })
    });    
});

and here is the button code (OnClick):

export function buttonAddress_click(event) {
    let $item = $w.at(event.context);
    let mapsURL = "someWebsite"
    + $item("#buttonAddress").label.toString().replace(" ", "+")
    + "," + $item('#textCity').text.replace(" ", "+");   
    //console.log(mapsURL);
    $item("#buttonAddress").link = mapsURL; 
}

You wrote:

.rep(" ", "+")

What is .rep() ?

my mistake :slight_smile: that was meant to be “replace” function

The question still stands, can anyone help please?

Hi :raised_hand_with_fingers_splayed:

You can do so by setting the target to blank.

$w('#button').target = '_blank';

Hope this helps~!
Ahmad

sorry, but as I wrote - no success with that

@mathgalago have you tried it with the repeater scoop instead?

$item('#buttonAddress').target = '_blank';

If this didn’t work then you’re probably setting up an invalid URL.

@ahmadnasriya thanks for the answer, but again - as I wrote above,
I tried it both ways ($item AND $w) - none of them worked.
Also - I checked the URL and it is OK, it works perfectly - only opens the URL in the current tab instead of a new tab.

@mathgalago
The URL must contain the base URL in order to open it in new tab, for example:

$w('#button1, #button2').target = '_blank';

$w('#button1').link = '/contact-us'; // This will still open in the same tab
$w('#button2').link = 'http://domain.com/contact-us'; // This will open in new tab

Please read more about the target.

@ahmadnasriya I know, the URL redirects to another website (not mine).
I can’t show my URL in the forum because my account credentials won’t allow it.

Is there a wix expert here to answer?

Anyone please? this is keeping me stuck