# On Lightbox Close \[Solved\]

**URL:** <https://forum.wixstudio.com/t/on-lightbox-close-solved/18903>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [September 26, 2019, 8:02pm UTC](https://forum.wixstudio.com/t/on-lightbox-close-solved/18903 "2019-09-26T20:02:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![geekbetting](https://avatars.discourse-cdn.com/v4/letter/g/3d9bf3/32.png) [@geekbetting](https://forum.wixstudio.com/u/geekbetting)\
**Post date:** [September 26, 2019, 8:02pm UTC](https://forum.wixstudio.com/t/on-lightbox-close-solved/18903/1 "2019-09-26T20:02:47Z")

</div>

Hello,

Is there a way to send data back to a page upon close? I know there is a way to send data on open of a lightbox, but unsure on the close side.

For example, I want to open a lightbox, have a user enter data, and then when the lightbox closes I want to refresh a repeater on the page. I need to refresh repeater to trigger / start when the lightbox closes.

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![givemeawhisky](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/givemeawhisky/32/5383_2.png) [@givemeawhisky](https://forum.wixstudio.com/u/givemeawhisky)\
**Post date:** [September 26, 2019, 8:05pm UTC](https://forum.wixstudio.com/t/on-lightbox-close-solved/18903/2 "2019-09-26T20:05:57Z")

</div>

**How do I pass data between a page and a lightbox?**  
When you open a lightbox using the [openLightbox()](https://www.wix.com/code/reference/wix-window.html#openLightbox) function, you can pass an object containing data to be used in the lightbox. In the lightbox’s code, you call the [getContext()](https://www.wix.com/code/reference/wix-window.lightbox.html#getContext) function to retrieve the data sent by the [openLightbox()](https://www.wix.com/code/reference/wix-window.html#openLightbox) function.

When you close the lightbox using the [close()](https://www.wix.com/code/reference/wix-window.lightbox.html#close) function, you can pass an object containing data to be used by the page that opened the lightbox. This data is retrieved from the resolution of the Promise returned by the [openLightbox()](https://www.wix.com/code/reference/wix-window.html#openLightbox) function.

[https://www.wix.com/corvid/reference/wix-window.lightbox.html](https://www.wix.com/corvid/reference/wix-window.lightbox.html)

---

<div class="post-metadata">

**Author:** ![geekbetting](https://avatars.discourse-cdn.com/v4/letter/g/3d9bf3/32.png) [@geekbetting](https://forum.wixstudio.com/u/geekbetting)\
**Post date:** [September 26, 2019, 9:28pm UTC](https://forum.wixstudio.com/t/on-lightbox-close-solved/18903/3 "2019-09-26T21:28:08Z")

</div>

Thanks for this. I’m getting the promise to trigger, but I keep getting a null error.

//Page Code:

```javascript
import wixWindow from 'wix-window';

export async function addPointButton_click(event) {
  $w('#addPointButton').hide();
  $w('#addPointSpinner').show();
 await wixWindow.openLightbox("AddPoint", {
 "row1": "hi"
  })
  .then( (data) => {
 //Wait for data coming back
    console.log(data)
  } );
  $w('#addPointSpinner').hide();
  $w('#addPointButton').show();
}

```

//Lightbox Code

```javascript
import wixWindow from 'wix-window';

$w.onReady(function () {
 let receivedData = wixWindow.lightbox.getContext();
    console.log(receivedData);
});

export function closeXButton_click(event) {
 let data = {"refresh_info": false}
  wixWindow.lightbox.close(data);
}

```

Any suggestions? I’m getting it to print “row1”: “hi” on lightbox open, but when it closes I’m getting null.

Thank you!

---

<div class="post-metadata">

**Author:** ![J.D](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j.d/32/7312_2.png) [@J.D](https://forum.wixstudio.com/u/J.D)\
**Post date:** [September 26, 2019, 9:46pm UTC](https://forum.wixstudio.com/t/on-lightbox-close-solved/18903/4 "2019-09-26T21:46:28Z")

</div>

@geekbetting I will guess you’re using the lightbox’s native X button that is set to close the lightbox without code. Try using a different button and see if it works,

---

<div class="post-metadata">

**Author:** ![givemeawhisky](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/givemeawhisky/32/5383_2.png) [@givemeawhisky](https://forum.wixstudio.com/u/givemeawhisky)\
**Post date:** [September 26, 2019, 10:05pm UTC](https://forum.wixstudio.com/t/on-lightbox-close-solved/18903/5 "2019-09-26T22:05:21Z")

</div>

@geekbetting  
For more on what J . D. means, have a look at the close function info from the API reference for it.  
[https://www.wix.com/corvid/reference/wix-window.lightbox.html#close](https://www.wix.com/corvid/reference/wix-window.lightbox.html#close)  
To pass data back to the page that opened the lightbox, you must close the lightbox programmatically using the close() function. If the lightbox is closed by the site visitor clicking the ‘X’ icon, close button, or lightbox overlay, data will not be passed back to the page that opened the lightbox. Therefore, if you want to make sure data is passed back to the page that opened the lightbox, [disable all of the methods mentioned above](https://support.wix.com/en/article/setting-how-your-lightbox-is-closed) and create your own method for closing the lightbox programmatically. For example, you can add a button with an onClick event handler that calls the close() function.

#### Close the lightbox and pass back data to the opening function

```javascript
import wixWindow from 'wix-window';

// ...

wixWindow.lightbox.close(dataObj);

```

Plus, there are a good many code samples in the Lightbox section that you can look at, like this in the close reference.

```javascript
/ *****************
 * Lightbox Code *
 ***************** /

import wixWindow from 'wix-window';

$w.onReady( function () {
  let received = wixWindow.lightbox.getContext();
  $w('#lightBoxReceive1').text = received.pageSend1;
  $w('#lightBoxReceive2').text = received.pageSend2;
} );

export function closeButton_click(event) {
  wixWindow.lightbox.close( {
    "lightBoxSend1": $w('#lightBoxSend1').value,
    "lightBoxSend2": $w('#lightBoxSend2').value
  } );
}

```

---

<div class="post-metadata">

**Author:** ![geekbetting](https://avatars.discourse-cdn.com/v4/letter/g/3d9bf3/32.png) [@geekbetting](https://forum.wixstudio.com/u/geekbetting)\
**Post date:** [September 27, 2019, 2:31pm UTC](https://forum.wixstudio.com/t/on-lightbox-close-solved/18903/6 "2019-09-27T14:31:53Z")

</div>

Thanks guys. I disabled [https://support.wix.com/en/article/setting-how-your-lightbox-is-closed](https://support.wix.com/en/article/setting-how-your-lightbox-is-closed) and then coded out a different X button and it worked perfectly. Thank you!!!
