Send data between the main page and a lightbox.
In this example, we open and close a lightbox using code, and send data between the main page and the lightbox.
We added the following to our site:
The code in this file enables you to send data to the lightbox and display data returned by the lightbox.
In this file, we create an event handler that is triggered when the button to open the lightbox is triggered. In this event handler, we:
Open the lightbox and send it the selected greeting and subject. On the same line, we save the lightbox's response.
Display the lightbox's response.
The code in this file displays the data sent from the main page to the lightbox, and enables you to send data back to the main page when closing the lightbox.
In this file, we:
import { window } from "@wix/site-window";
$w.onReady(() => {
$w("#openLightboxButton").onClick(async () => {
const dataToSend = {
greeting: $w("#greeting").value,
subject: $w("#subject").value,
};
const lightboxResponse = await window.openLightbox(
"Greeting Lightbox",
dataToSend,
);
$w("#returnedMessage").text = `YOU CHOSE: ${lightboxResponse}`;
$w("#returnedMessage").show();
});
});
Join the Wix Studio community on Discord, where experienced developers and fellow creators come together to share tips, troubleshoot issues, and collaborate.
Building a coded solution on your own can be challenging. Let an experienced Wix developer build it for you, so you can keep working on your site or business. Visit the Wix Marketplace to find a trusted developer.