# Lightbox not closing via main code

**URL:** <https://forum.wixstudio.com/t/lightbox-not-closing-via-main-code/54593>\
**Category:** Ask the community\
**Tags:** wix, question, wix-studio, code\
**Created:** [December 15, 2023, 12:24am UTC](https://forum.wixstudio.com/t/lightbox-not-closing-via-main-code/54593 "2023-12-15T00:24:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![coz](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/coz/32/25023_2.png) [@coz](https://forum.wixstudio.com/u/coz)\
**Post date:** [December 15, 2023, 12:24am UTC](https://forum.wixstudio.com/t/lightbox-not-closing-via-main-code/54593/1 "2023-12-15T00:24:47Z")

</div>

**Question:**  
[**Lightbox will not close via code once opened.**.]

**Product:**  
[Velo ,wix editorX.]

**What are you trying to achieve:**  
[simply close the light box via code once opened not with a user click element input]

**What have you already tried:**  
import wixWindow from ‘wix-window’;

$w.onReady(function () {  
// Open the lightbox  
wixWindow.openLightbox(‘Promo’);

```
// Set a timeout to close the lightbox after 3 seconds
setTimeout(function() {
    wixWindow.lightbox.close();
}, 3000); // 3000 milliseconds = 3 seconds

```

});

**Additional information:**  
[ The lightbox displays but will not close via program code. Settings in lightbox on and off seem to have no effect on the outcome. Only closing with button triggers from the lightbox works. I need to do it from the main code. For clarity, I am not trying to close it with any click element from within the code. I assumed that `wixWindow.lightbox.close();` would simply close the box if open from the main code. I have tried passing data to to use code and close the lightbox within it directly, but that fails too, giving no error trap. I have tried different browsers Edge by default and Safari and Chrome all do the same in out of editor  
Any help would be appreciated .Thank you.

example standard lightbox ‘Promo’ with this code does not close. …[Home | My Site (myminxsite.editorx.io)](https://myminxsite.editorx.io/mylightbox)

---

<div class="post-metadata">

**Author:** ![Dan\_Suhr](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/dan_suhr/32/94074_2.png) [@Dan\_Suhr](https://forum.wixstudio.com/u/Dan_Suhr)\
**Post date:** [December 15, 2023, 3:17am UTC](https://forum.wixstudio.com/t/lightbox-not-closing-via-main-code/54593/2 "2023-12-15T03:17:00Z")

</div>

try

```javascript
import {lightbox} from 'wix-window';

$w.onReady(function () {
    setTimeout(function(){ 
        lightbox.close();
    }, 3000);
});

```

---

<div class="post-metadata">

**Author:** ![coz](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/coz/32/25023_2.png) [@coz](https://forum.wixstudio.com/u/coz)\
**Post date:** [December 15, 2023, 6:33am UTC](https://forum.wixstudio.com/t/lightbox-not-closing-via-main-code/54593/3 "2023-12-15T06:33:55Z")

</div>

Thank you for trying to help, it did not close the Lightbox, only importing that specific part of the module.

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [December 15, 2023, 11:36am UTC](https://forum.wixstudio.com/t/lightbox-not-closing-via-main-code/54593/4 "2023-12-15T11:36:46Z")

</div>

> [@coz](#):
>
> [import wixWindow from ‘wix-window’;
> 
> $w.onReady(function () {  
> // Open the lightbox  
> wixWindow.openLightbox(“Fumble Feild”);
> 
> ```javascript
> // Set a timeout to close the lightbox after 3 seconds
> setTimeout(function() {
> wixWindow.lightbox.close();
> }, 3000); // 3000 milliseconds = 3 seconds
> 
> ```
> 
> });

The following code works and has been tested…

```javascript

import wixWindow from 'wix-window';

$w.onReady(function () {
// Open the lightbox
	setTimeout(function() {
		wixWindow.openLightbox('myLightbox');
	}, 3000); // 3000 milliseconds = 3 seconds

	// Set a timeout to close the lightbox after 3 seconds
	setTimeout(function() {
		wixWindow.lightbox.close();
	}, 6000); // 3000 milliseconds = 3 seconds
});

```

---

<div class="post-metadata">

**Author:** ![coz](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/coz/32/25023_2.png) [@coz](https://forum.wixstudio.com/u/coz)\
**Post date:** [December 15, 2023, 4:03pm UTC](https://forum.wixstudio.com/t/lightbox-not-closing-via-main-code/54593/5 "2023-12-15T16:03:36Z")

</div>

This code does not close programmatically for me in three different browsers, even though I’ve copied and pasted it exactly. I’ve even renamed ‘Fumble Field’ to ‘myLightbox’ to match the code exactly. Increasing `}, 6000);` to 6 seconds just delayed the exit but never actually closed it, just as before. Can I just check if you have triggers set to close by a button or user interaction, or any other code in myLightbox itself? Are you running it in the editor ? There isn’t much room for error, as the code should be straightforward. It’s very frustrating. Thanks again.

example standard lightbox with this code does not close. …[Home | My Site (myminxsite.editorx.io)](https://myminxsite.editorx.io/mylightbox)

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [December 15, 2023, 6:12pm UTC](https://forum.wixstudio.com/t/lightbox-not-closing-via-main-code/54593/6 "2023-12-15T18:12:00Z")

</div>

Ok, maybe i did not pay 100% attention on …

![2023-12-15 19_04_02-Lightbox not closing via main code - Discussion _ Ask a question - Wix Studio Co](https://us1.discourse-cdn.com/wix/original/3X/a/7/a7c521bfc4baac98ad4f7871616a879267837ebd.png)

So you are using Editor-X. I did my testing on ordinary one.

However, now i did the same on Editor-X and found further strange behaviour.

SETUP:

1. Editor-X
2. Ordinary Lightbox (nothing else)
3. No buttons
4. Working code (inside LIGHTBOX)

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

$w.onReady(function () {
// Open the lightbox
	setTimeout(function() {
		wixWindow.openLightbox('myLightbox');
	}, 3000); // 3000 milliseconds = 3 seconds

	// Set a timeout to close the lightbox after 3 seconds
	setTimeout(function() {
		wixWindow.lightbox.close();
	}, 10000); // 3000 milliseconds = 3 seconds
});

```

1. And the most important setting →   
 ![2023-12-15 18_58_41-Wix Website-Editor _ examples](https://us1.discourse-cdn.com/wix/original/3X/f/5/f51fdf1eae2436e24fedb82b589c33ebf7cfe005.png)  
Automatic displaying of the LIGHTBOX → (YES or NO)  
a) If you activate the automatic LIGHBOX-POP-UP → The lightbox do show  
b) If you deactivate the auto-POP-UP → The lightbox will never show, even controlled by code. It will never pop-up.

However → the CLOSE-Function do still work, if you have the auto-POP-UP setted to → **ON**.

Example can be seen here… (in this example the auto-pop-up is set to **YES** and after 10sec. the LIGHBOX will close.  
[https://russian-dima.editorx.io/examples/blank](https://russian-dima.editorx.io/examples/blank)

**At least the CLOSE-FUNCTION works.**

**@Wix →**   
b) If you deactivate the auto-POP-UP → The lightbox will never show, even controlled by code. It will never pop-up.

**WHY ???**
