Hi everybody!
I created a preloader that opens a lightbox when another page is called from the menu (My menu is created by myself with buttons).
With that menu-click I set a local variable to “true” and call the lightbox.
In the code of every page I change this local variable once the page is loaded to “false” and the now still open lightbox checkes this variable with a setInterval function.
If the local variable changes from “true” to “false” the lightbox closes and the new page is there, ready and loaded.
Basically this works BUT I always get the error: “Uncaught (in promise) Lightbox is open”
This error stops any further action (such as saving to database, etc.) on that newly opened webpage.
So it seems that calling the lightbox opens a promise that remains unsolved, because the page is changed while the lightbox is still open.
I tried to use preloaders with code being loaded in the header (as proposed in many postings), but such a preloader only starts when the new page starts loading and not right after the menu is clicked.
Anybody got an idea on how to get rid of the error message - or a preloader that opens when the menu is clicked and not when the new page starts loading and stays until the new page is loaded?
Any ideas?
Thanks!
******Code on old page where the button is clicked **********
export function menuKlaBtn_click ( event ) { //This is a menu button
pagLoadOpen (); //calls the function to open the lightbox and sets a local var to “true”
wixLocation . to ( “/account/ensembles” ); //redirects to another page
}
function pagLoadOpen () {
local . setItem ( “loading” , “true” ); //sets a local var to “true”
wixWindow . openLightbox ( “pageLoader” ); //opens the lightbox
}
Code on new loaded page****
import wixWindow from ‘wix-window’ ;
import wixLocation from ‘wix-location’ ;
import { local } from ‘wix-storage’ ;
$w . onReady ( function () {
…
pagLoadClose (); //is called when the page is loaded
}
function pagLoadClose () {
local . setItem ( “loading” , “false” ); //just changes the local var
}
Code in Lightbox “pageLoader”*
import wixWindow from ‘wix-window’ ;
import { local } from ‘wix-storage’ ;
$w . onReady ( function () {
setInterval ( function (){ //checks the locals var “loading” every 500ms
let val = local . getItem ( “loading” );
if ( val === “false” ) {
wixWindow . lightbox . close (); //closes the lightbox
}
}, 500 );
});
******** ERROR in console after new page is loaded***
Uncaught (in promise) Lightbox is open