i added a Button to my site which links to a function. That function builds an URL depending on the data a user entered and then opens this url preferrably in a new window/tab.
I used the wixlocation.To() subroutine to call the url but it always gets opened in the same window. I want a new window. How can this be done?
You can change the functionality of links using the functions described in $w.LinkableMixin . Keep in mind that the behavior of new tabs/windows is often a browser setting.
On a database populated table, I open up a lightbox if the condition in my dataset is set to “popup”. If the condition is “redirect”, I want to open a URL in a new tab or browser. Right now, it opens in the same browser. It doesn’t look like I can use target on a table.
export function table1_rowSelect() {
setTimeout(() => { let itemData = $w(“#dataset1”).getCurrentItem(); if (itemData.type.action===“Popup”){
wixWindow.openLightbox(“Media”, itemData);
} else if (itemData.type.action===“Redirect”){
$w(“#table1”).target = “_blank”; ← I get an error in the IDE
wixLocation.to(itemData.location);
}
}, 2000);
}
@brett82 No, you can’t set target for a table. However, you can use link/target on some components such as Button and Image . For more information, see the LinkableMixin API .
Hello, I have a similar question about how to use code to have a button open a PDF in a NEW browser window, but making the browser tab with the PDF the CURRENT browser window. I know very little about WixCode (or code in general) so any advice is greatly appreciated. My question is posted here:
let i=event.itemIndex
$w(“#dataset2”).getItems(i, 1) .then( (result) => { l et items = result.items;
event.item.target=“_blank”
event.item.link=“/events/”+items[0].title
} )
does not work also
Hello coders! I have question related to this subject: I am using the Onclick event to trigger facebook tracking and then wixlocation.to to go an external link. I would like the link to open in a new window and I can’t get it to work. When I use the button’s set “link and target” inside onReady it works but then, when I add the Onclick it stops working. Is there a way to have the “link and target” inside the Onclick? something like this?
I have the same issue. You can have a button open a link in a new window by resetting the target to _blank but as soon as you add an OnClick event it no longer works. It also doesn’t work if you attach the button to a dataset on the page. The only way I have been able to make the target _blank work is on a button with no code attached to it.
You can’t do it in the OnClick event because wixLocation.to() doesn’t accept the target attribute.
I am trying to have the button open an external site in a new tab but need code on the button to write to my data collection