Lightbox bug

Cannot open lightbox again, after switching from one lightbox to another lightbox by code

I open a lightbox by a button

Then open the second lightbox, by clicking a button in the first lightbox that direct me to the second lightbox

Then close the second light box.
Afterwards, I can’t open the second lightbox again. The second lightbox become unresponsive

This is the website that demonstrate the problem.

https://jeffreygd.editorx.io/lightboxtest

See if this works for you.

Only if I do not switch to the second lightbox, and close at the first lightbox, then I can open the second lightbox again.

I use this way to collect information at different lightboxes.
Actually it worked before, just that it didn’t work one day suddenly, so I suspect there is a bug.

Please help to see if there is any bug at the lightbox, thank you.

I see the problem.
Maybe it’s a bug, you can report it.
But meanwhile you can try closing the first lightbox by code together with opening the second one.
This is the error you get when you try to reopen the 2nd lightbox:

Hey guys,
I am also facing the same issue. I tried implementing the solution mentioned above with this code.

export function CloseButton_click ( event ) {
wixWindow . lightbox . close ();
wixWindow . openLightbox ( “Lightbox 2” );
}

It works well in the preview mode but does not work on the live site for some reason. Let me know if I’m missing something

@dilip I don’t know if this solution works or not (it’s a long shot), but you should wrap it in Promise.all :

export function CloseButton_click(event) {
Promise.all([
    wixWindow.lightbox.close(),
    wixWindow.openLightbox("Lightbox 2")
]);
}

P.S. It is probably a bug that you should report

I think that in order to get this to work you will have to add the code to open the second lightbox to the page code where you opened the lightbox originally. Technically once the lightbox is closed the page code for that lightbox is terminated. Meaning it would not see the line to open the second lightbox.

Since you can not open a lightbox while another one is already opened we can also not call that line of code before closing the existing lightbox. Therefore we have to have an intermediary to process the redirect successfully.

One thing you could try is passing a data object into the close function that contains the name of the second lightbox you would like to open. That would look something like this:

Lightbox page:

export function close() {
    let newLightBox = "lightBox2"
    wixWindow.lightbox.close({data: newLightbox});
}
Page code:
wixWindow.openLightbox("lightBox1)
.then((received) => {
    wixWindow.openLightbox(received.data)
})

I have not tried this bit it should work based on the following recourses:
openLightbox - Velo API Reference - Wix.com
close - Velo API Reference - Wix.com

Also something cool is that the lightbox will not pass the data object back to the page if it is closed with the “X” or by clicking on the background. This makes the close function especially easy to bind to a button. You could also (in theory) have multiple lightboxes with the ability to go back or foreword to a previous lightbox.

@jonatandor35 I have reported it to WIX customer care, and after review she said will report it to the team to check the bug. Will see how the reply goes. Thank you.

This code solution does work – just tried it, as I have been experiencing the same error. However, I have linked light boxes with data successfully in the past without having to resort to this method. So something changed under the covers in Wix since the last time I did this (July, 2021).

We also encountered this BUG, and still not fix yet, which making our website malfunction as we rely on this feature. Wix change something under the covers and not informing us.

And the most annoying thing is, the openLightbox function cannot handle opened lightbox, and Wix don’t have closeLightbox function as well to force some opened lightbox to close.

This is just simple UI control features, and should be easy for Wix engineer to implement.

Please see my comment above

@amotor

Thanks Amotor, our case cannot use your method, as we need to pass data to first lightbox, and then pass data from first lightbox to second lightbox. So we cannot use close lightbox function inside first lightbox.

Even though WIX can close first lightbox properly and open second lightbox, but the BUG will be triggered at the moment when user close the second lightbox. And then the second lightbox never close and no way to force it to close, user need to reload the whole page from browser.

Of course if user try to open second lightbox again, same error prompt as J.D. encountered.

@cmonlai
you can just pass the values to the parent element using the data object on the close function of the first lightbox like so:

wixWindow.lightbox.close({data: yourDataHere})

https://www.wix.com/velo/reference/wix-window/lightbox-obj/close

Then on the parent page just pass the data into the second lightbox with

wixWindow.openLightbox("name", {data: yourDataHere})

Trying to open one lightbox directly from another open lightbox is not possible and will give you the errors that you are seeing. The parent page HAS TO BE the intermediary to handle opening and closing of multiple lightboxes and passing data between them. There is no other way to accomplish this task

@amotor

oh yeah you are so smart bro!

We just rewrite our code and it works smoothly, thanks lot!

I think your suggested way is the most proper way for multiple lightboxes switching. The method we used before was bypassing WIX system hierarchy, so actually we were lucky to use our old method and kept worked for few years XD

@davebogan98 After I reported it, WIX still hasn’t fixed it (1st April 2022). Maybe you could report as well. See if more people reporting will work.

The solution above is correct, and able to pass data between (or use memory to save data). But if I want to switch forward and also backward between lightboxes, it becomes complicated.

At the end I use the “Multi-state box” element instead of lightboxes (put a Multi-state box in a lightbox), as it can switch between “states” easier, and save data in the same page. Plus it is faster to load between “states” than between lightboxes.

So the solution I use is a mix of above code if I really need to switch between lightboxes, and “Multi-state box” for continuous lightboxes.

“Multi-state box” is in EditorX, and I believe “slideshows” is for WIX editor.
I wish WIX will fix the bug so it can go back to the way it was, which is easier to code :worried:

@jeffrey22 You can use multi-state boxes in the regular Editor – I use them in several places. I’ll try to send in a bug report on the lightbox issue.

I’m having this same issue now =\

see my comment below: https://www.wix.com/velo/forum/main/comment/ecc32d3c-cd9a-393f-9f4d-eabb37484e2d?postId=622752a3652eaa001608cb60

I fixed it… no where does it say that you have to enable the onReady in the code window when you’re using straight code lol.