Help with detecting when Lightbox is not in DOM anymore

Hi all,

I have a lightbox on a page which is triggered in certain situations to protect the content on the page. When a trigger occurs, the lightbox is opened and covers the entire page. When the user clicks the exit button, a function executes some code, then the lightbox closes and the content on the page is revealed again.

The behaviour described above works well and I am happy with that. However, the issue I am encountering is that the user can always right click → inspect the lightbox and delete it from the DOM. When the user does that the function (which was supposed to be executed when the exit button was clicked does not run - obviously).

My question is: is there a way to detect when the lightbox disappears from the DOM, so I can still call the function associated with the exit button?

What I have tried so far:

  • I have tried opening the lightbox once the user deletes the lightbox from the DOM, but Velo is still saying the Lightbox is open, so that doesn’t work

Any help much appreciated

I don’t think there’s a simple way to detect it.
You should handle it differently.
Please provide more details regarding what you’re trying to achieve