Search.../

getContext( )

Returns the data object that was passed to a lightbox.

Description

The getContext() function returns the data object passed when the lightbox was opened using the openLightbox() function, if any data was passed. If the lightbox was opened another way, getContext() returns undefined.

To pass data to the lightbox that is opened, you must open the lightbox programmatically using the openLightbox() function. If the lightbox is opened automatically when the page loads or by a link from a page element, data will not be passed to the lightbox. Therefore, if you want to pass data to the lightbox, make sure Automatically display lightbox on pages is set to No in the Lightbox Settings panel in the Editor and don't set any element's link to open the lightbox. Instead, create your own method for opening the lightbox programmatically. For example, you can add a button with an onClick event handler that calls the openLightbox() function.

Syntax

function getContext(): Object

getContext Parameters

This function does not take any parameters.

Returns

The data object that was passed to the lightbox.

Return Type:

Object

Was this helpful?

Get the data that was passed to the lightbox

Code Example

Copy Code
1import wixWindow from 'wix-window';
2
3// ...
4
5let receivedData = wixWindow.lightbox.getContext();
A scenario where information is passed between a page and a lightbox

This example demonstrates how to pass data from a page to a lightbox that it opens and from the lightbox back to the page as it closes.

It assumes that the page has:

  • An open button that is used to open the lightbox.
  • Two text inputs where information that is to be passed to the lightbox is entered.
  • Two text elements where information that is passed from the lightbox is displayed.

It assumes that the lightbox has:

  • A close button that is used to close the lightbox.
  • Two text inputs where information that is to be passed to the page is entered.
  • Two text elements where information that is passed from the page is displayed.

Code Example

Copy Code
1/*************
2 * Page Code *
3 *************/
4
5import wixWindow from 'wix-window';
6
7export function openButton_click(event) {
8 wixWindow.openLightbox("MyLightBox", {
9 "pageSend1": $w('#pageSend1').value,
10 "pageSend2": $w('#pageSend2').value
11 })
12 .then( (data) => {
13 $w('#pageReceive1').text = data.lightBoxSend1;
14 $w('#pageReceive2').text = data.lightBoxSend2;
15 } );
16}
17
18
19/*****************
20 * Lightbox Code *
21 *****************/
22
23import wixWindow from 'wix-window';
24
25$w.onReady( function () {
26 let received = wixWindow.lightbox.getContext();
27 $w('#lightBoxReceive1').text = received.pageSend1;
28 $w('#lightBoxReceive2').text = received.pageSend2;
29} );
30
31export function closeButton_click(event) {
32 wixWindow.lightbox.close( {
33 "lightBoxSend1": $w('#lightBoxSend1').value,
34 "lightBoxSend2": $w('#lightBoxSend2').value
35 } );
36}
37