I have a button that triggers (connected to) a Lightbox but I ALSO want that button to redirect to an external link 2 seconds after clicked (so the button has two actions basically, pop-up then redirect). It’s already connected to the Lightbox, I just need the code for redirection after 2 seconds.
I am totally new to Wix but I can get to the dev code ( Please see attached) and the button id is #button3
import wixWindow from 'wix-window';
export function button1_click(event) {
let data = {
url: 'https://www.google.com' //url to redirect to
};
wixWindow.openLightbox('lightboxName', data); //open lightbox using name
}
After this, remove the trigger from your lightbox and use the following code inside the lighbox.
import wixLocation from 'wix-location';
import wixWindow from 'wix-window';
$w.onReady(function () {
let pmtdata = wixWindow.lightbox.getContext();
if(pmtdata) {
setTimeout( () => {
wixLocation.to(`${pmtdata.url}`);
}, 2000); //2000 milliseconds
}
});
@aalaliwi To open a link in a new window you can use the Button’s target property but you cannot do that with the above method as that will not open a lightbox and wait for 2 seconds.
I am facing a similar issue… would you have any keys n mind ito unlock it?
Thanks so much in advance
Details here:
Here also I want to have a CTA with 2 functions.
The first would be to share a post of Facebook. The second would be to direct the user to another page on the website where he could get a reward after having shared the post on FB.