Dynamic Page and target blank

The link on a table linked to a dynamic page , does not open the new page on empty target. Why?

And it doesn’t even work with the “link parameter” anymore…


$w("#mybutton").link = "https://miosito.com";
$w("#mybutton").target = "_blank";

Before it worked, now not

Thanks
Claudio

This has been asked in the forum previously and was mentioned recently too, so have a search of the forum and you should find those previous posts.

Like this one here.
https://www.wix.com/corvid/forum/community-discussion/how-to-link-a-button-using-code

However, the answer was to put the target part of the code from the LinkableMixin API into your pages onReady function (see in above link.)
https://www.wix.com/corvid/reference/$w.LinkableMixin.html

Plus, you can’t mix it up with the Wix Location API and the to function as well.
https://www.wix.com/corvid/reference/wix-location.html#to

Although, unless something has changed you should be opening that in a new tab already anyway.
Link targets are only supported for external web links (e.g. http://www.wix.com)..)

if you are trying to open another page from your website and have it setup like this, then it will open in the same window. $w(“#myElement”).link = “/about-me”;

Set an element to open an external web link in a new browser page when clicked

$w("#myElement").link = "http://wix.com";
$w("#myElement").target = "_blank";

Thanks GOS for many explanations, but this solution doesn’t work for me, why?
Nothing is happening, does not open any page.

export function button174_click(event) {

    $w("#button174").link = "http://wix.com";
    $w("#button174").target = "_blank";
}

Also, why this configuration don’t works for dynamic page tables connection?
Opens the page, but not in a new one

Thanks a lot
Claudio

It makes no sense to set the destination of a link after it has already been clicked. That’s what you’re trying to do with that code. As GOS said, set the destination of the link in the onReady handler (it could be some other event also - but it can’t be the click event of the button in question). Essentially just copy and paste the two lines you already have and place them into the onReady handler that exists by default for every new page you create.

One thing I just discovered is that if you have an onClick handler for the button, it takes precedence over any .link and .target specification you may make in your onReady handler. I have a page with a link that does two different things depending on whether you are an admin or a regular member of the website. Because of this precedence behavior I can’t reuse the button to do two different things. Instead, I must create a second button that sits on top of the first one and I show/hide the appropriate one depending on who is logged in.

Bottom line, Claudio you should detach your button174_click(event) handler from the button otherwise it won’t work!

i think you have the precedence thing right but not the idea that one button can’t do different things. You’d either set the link property or add an onClick handler but when you do this you can determine if the current user is privileged and set the appropriate value/behaviour.

@lee1 You would think so but there is no target option for wixLocation.to(). If you want one of your options to open a new tab, then you need to use my approach. Frankly Wix should just do the right thing and expose a target option but they’ve convinced themselves that this is the way it should be .

@gym Why can’t you set the link property to the appropriate value depending on privilege level?

@lee1 Thank you, it’s working now and it’s an excellent alternative.

The anomaly remains when you click the table (via the Settings Table panel) to open a dynamic page on a new one. We hope they solve it soon.

Thanks again