Button to Redirect 2 Seconds After Clicked

Hi,

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

Thank you.

Unlink the button to the lightbox. Create an onClick event for the button using the properties panel .

Your page code will look like this:

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
   }
});

Shan,

Thank you so much! It works perfectly! One more thing, how could I get the new link to open in a new tab?

@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.

@shantanukumar847 Got it. Thanks a lot, Shan!

@shantanukumar847 Hi Shan, saw you helped a lot in here

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.

Example of this working :

Would you know how to do that on a Wix CTA ?

Thank you for yout help
Take care