How to redirect after closing a lightbox?

Hello,
I have a form which show a lightbox after submission to confirm it. I want to redirect to another page after that

1st solution : the user submit the form → the lightbox appears → the redirection comes after the user click the close button of the lightbox.

2nd solution : I can also redirect to another page after a delay : the user submit the form → the lightbox appears → after 5 sec, the lightbox disappear and the user is redirected.

How can I do the 1st or 2nd solution and which one is the easiest way? Thanks

I put this code on the lightbox page but it doesn’t work :

import wixLocation from ‘wix-location’;

$w.onReady( function () {
//TODO: write your page related code here…
});

//when I click anywhere on the lightbox page
export function page1_click(event, $w) {
wixLocation.to(“/les-chantiers-1”);
}

//when I click on the X button of the lightbox
export function button2_click(event, $w) {
wixLocation.to(“/les-chantiers-1”);
}

Any help?

Hi,
You should open the lightbox using code and redirect to the page as demonstrated below:

wixWindow.openLightbox("LightboxName") 
.then( () => {
    wixLocation.to("/les-chantiers-1"); //page name
} );

Best,
Tal.

I have a form that opens in a lightbox. After the form is submitted, and the user closes the form (with the x) I want to redirect to a Thank You page. How do I modify the code above for this?

Hello Therese,

Your initial button should only open the lightbox as Tal has mentioned, and pass in data from the form to that lightbox, then you get the context of the lightbox (the data passed in). The button in the lightbox should be the actual submit button and for that there is a ready option that lets you redirect after successful submission, see here:

To Recap:

  1. Opening Lightbox and passing in data - here

  2. Create button in the lightbox that acts as the
    submit button and redirects on success

Goodluck,
Majd

Thanks. I already have the button configured to an automation (send an email). What I am trying to do is have user redirected to a thank you page AND get the email. Is that possible with the lightbox?

Any ideas on the question from Therese above? I have the exact same problem. I’m trying to deliver a code to the user via a lightbox, but I want them sent to the home page. Any ideas? I appreciate it!

Just do what Majd has stated above and set the link from the submit button to your home page.

The triggered email or automated email, whichever one you are using, will still work as it runs when the submit button is pressed.

Thanks! That did work.