Hi;
I want the light box to be closed only with the close button. What should I do about this or can you send a sample page code?
Currently, except for the close button, the user can close by clicking esc or any space. I just want it to close with the close button.
Alternatively, I found a code, but that code doesn’t do exactly what I want. Because the box never closes.
here is the code
import wixWindow from 'wix-window';
$w.onReady(function () {
//TODO: write your page related code here...
neverExit();
});
function neverExit() {
wixWindow.openLightbox('Premium')
.then((data) => {
if (!data || !data.forceExit) {
neverExit();
}
});
}
Actually what I want to do is;
1- Log in lightbox (requests the visitor to be a member or log in.) If a member is logged in, the lightbox will not appear on the page
2- If the member role is not premium, the premium lightbox will be opened. If the member role is premium, the light box will not be opened.
A sample code or a redirect that will enable lightboxes to open as I wish will be useful to me.
#userrole #role #lightbox
I am using the following code for the login lightbox. But I can’t do what I want for the issues I mentioned above. Because the visitor can disable the lightbox by clicking esc or any space.
$w.onReady(() => {
if (wixUsers.currentUser.loggedIn) {
wixWindow.lightbox.close('Login');
} else {
wixWindow.openLightbox('Login');
}
});
Hi 
You don’t need a code to do this, you can use the lightbox settings panel to control how the lightbox is closed, this also apply to the “Close Button”, you can add it from the lightbox settings.
You can also close the lightbox by adding an onClick() event handler to any element, for example a vector image (X).
$w('#closeVector').onClick((clickEvent) => {
wixWindow.lightbox.close();
})
You still need to import Wix Window module if you haven’t already.
import wixWindow from 'wix-window';
Hope this helps~!
Ahmad
Hi,
Currently, there is no way to prevent the escape key from closing the light box.
Feel free to submit this feature to the wishlist so others can vote for it and make it happen!
Thanks for the answer. This gave me more ideas.
I was able to do this, which is working for your exact scenario.
I also have a subscription/premium only page and am using a custom login lightbox (not the WIX default)
Here is the code, copy this into the code of the premium page. If the user is logged it, it will not display the Lightbox. If the user hits esc, close, or alternatively, it will close and automatically reopen the lightbox.
import wixWindow from ‘wix-window’ ;
if (! wixUsers . currentUser . loggedIn ){
startLogin ()
}
export function startLogin (){
wixWindow . openLightbox ( “Lightbox Login” )
. then ( ( data ) => {
if (! wixUsers . currentUser . loggedIn ){
startLogin ()
}
});
}