Hi,
I have this code on a lightbox.
It supposed to show the message “msg”.
But if the messege is “close” then it supposed to close the lightbox.
I first open the lightbox from some page sending a msg.
then, after some time, the page opens the same lightbox but with the “close” msg.
Sttrangely, the lightbox stayes open.
the console log does show “closing…”.
Why doesn’t the lighbox close?
import wixWindow from ‘wix-window’;
$w.onReady(async function () {
let msg = wixWindow.lightbox.getContext()
if (msg) {
$w('#txtMsg').text = msg
}
if (msg == "close") {
wixWindow.lightbox.close()
console.log("colsing...");
}
});
Try
import { lightbox } from 'wix-window';
$w.onReady(async function () {
let msg = lightbox.getContext()
if (msg) {
$w('#txtMsg').text = msg
}
if (msg == "close") {
lightbox.close()
console.log("closing...");
}
})
1 Like
Hi, tiktik17 !!
I haven’t conducted such experiments with Lightboxes, so I can’t say for sure, but isn’t it possible that the newly opened Lightbox is closed while the original one remains open? You might be imagining that the Lightboxes being opened are the same, but if you think of them as instances with different IDs, this interpretation might make sense. I haven’t tried it myself, so I’m not certain. However, if you’re considering remotely closing a Lightbox from the page, you could try using wix-storage
or wix-realtime
to send a message. 
P.S.
What purpose are you trying to achieve by closing the lightbox from the page?
If you want the flexibility to open and close it dynamically, you might not need to force yourself to use a lightbox. Instead, you could pin a container to the page and use it in a lightbox-like. 
2 Likes
Ah, If that is what they are trying, I am wondering how they are triggering that from the page. The lightbox’s overlay would prevent any UI interaction on the page. right?.
If they are using a setTimeout() in the page code. then that should be moved to the lightbox’s page code, and just set to close the lightbox.
import { lightbox } from ‘wix-window’;
$w.onReady(async function () {
let msg = lightbox.getContext()
setTimeout(() => {
closelightbox()
}, 5000);
function closelightbox (params) {
console.log("CLOSING")
lightbox.close();
}
})
I get the real-time scenario, which affect everyone, every where who is viewing the lightbox.
Why wix-storage?.
1 Like
Ah, I just thought using wix-storage could make it easier to send and receive messages. If you set up a loop with setInterval
on the lightbox side to monitor wix-storage, it could be done. However, like Mark, I’m not entirely sure why we would need to do this (close the lightbox from the page via a message) or how it would work. For example, if there was a loading indicator in the lightbox showing ‘Loading…0%’ to ‘Loading…100%’, there might be a use case where the page sends continuous values, and once it reaches 100%, the lightbox closes. Or maybe there’s a use case where you want to close the lightbox from a message sent from a Wix site opened in a different tab. But for now, it seems fine to end the discussion here. 
2 Likes