wixLocation.to(url) opens url in same tab even with button target = "_blank"

I have a url that is generated by an api that is called within a button and I want to open the url in a new tab.
My code currently looks like this:

$w.onReady(function () {
 let id = wixLocation.query["id"];
 wixData.query("contact012").eq("_id", id).find().then((result) => {
     let url = result["_items"][0]["url"];
     $w('#button').onClick(() => {
         pdf(result["_items"][0]["firstName"], url).then(e => {
             $w('#button').target = "_blank";
             $w('#button').link = e;
             wixLocation.to($w('#button').link);
         });
     });
 });
});

I’ve tried doing just

wixLocation.to(e);

but nothing seems to work, any help would be greatly appreciated :slight_smile:

EDIT: Is it possible to call the link funcitonality from the code? I found the doccumentation for linkableMixins but you cant call it.

wixLocation.to() doesn’t work with .target.
$w(‘#button’).target = “_blank” is for the link only.
You can’t open a new tab as a results of promise fulfillment using pure Corvid.
You can do it if you create a custom element with window.open(link, “_blank”) that is triggered when you set the custom element attribute to a specific value.
Even if you go for this direction Mozilla Firefox will block the new window by default as there’s a delay between the click and the window.open().
If you want to be able to work on Firefox as well you should create the button in the custom element itself and once it’s clicked the event handler open an empty window like:
let win = window.open(“”, ‘_blank’);
And once the promise results are received you assign the link:
win.location = link;
But it’s an annoying back&forth.

Did you manage to fix this?

This is NOT a bug, please use custom element or native button(not using code)

I’m no coder, only know basic js and I haven’t used html. I’d like the user to click a social media icon and share the current page on a new tab. Is a custom element the best path for this? Can you help with an example?