Age verification Pop UP (Solved)

Hi to all.
I’m newbie about coding and JS.
I need to add a popup with “age verification” inside the SITE code.
A simple question that ask if the user is over or under 18 years old.
With 2 buttons 1 to accept and continue to the site, 2 to leave.

I need this features:

  1. The popup must appear EVER in any page of the site.
  2. Must have a dark overlay that hide the contents of the page
  3. It must not be bypassed or skypped in any way
  4. When the user click on “+18” buttons, the confirmation are saved on storage session of the browser and the popup will not appear until the end of the session
  5. The portion of the code must be executed before the loading of page elements (and other lightbox) and before another script that i need in the page.

I tryed with a normal lightbox in wix and then i added this code to the SITE panel:

setTimeout( function () {
if (!session.getItem(“firstTimePopupShown”)) {
// open popup
wixWindow.openLightbox(“alert18”);
// set flag for future visits
session.setItem(“firstTimePopupShown”, “yes”);
}
// The timeout value is 300 nanoseconds
},
300);

Unfortunately this is not good for my purpose:
when the user leave the page and press back button on the browser…the script read the label “firstTimePopupShown” in the session storage, and never appear.

So i think that i need to add “session.setItem” as a fuction to the button +18 of the lightbox.
In this case the script add the label to the session storage only if the user confirm that is older than 18y.
But I have no idea to do this.

Please…anyone can help me?

Thanks so much.

https://support.wix.com/en/article/corvid-tutorial-creating-a-one-time-popup

https://www.wix.com/corvid/forum/community-discussion/one-time-pop-up-1

thank you so much! A whisky for you :slight_smile:
But this not working for me. I solved with this:

Create a ligtbox named “age18-alert” and put into 2 buttons.
At the buttons +18 I assigned “OnClick” event that close the lightbox and set the “session.setitem” to “FirstTimeAgeVerification”: Like this:

export function buttonOnAge(event) {
wixWindow.lightbox.close(‘age18-alert’);
// set flag for future visits
session.setItem(“FirstTimeAgeVerification”, “yes”);
}

Finally in the SITE panel i added this code:

import {session} from ‘wix-storage’;
import wixWindow from ‘wix-window’;

$w.onReady( function () {

// flag is not found
setTimeout( function () {
if (!session.getItem(“FirstTimeAgeVerification”)) {
// open popup
wixWindow.openLightbox(“age18-alert”);
}
// The timeout value is 3000 nanoseconds
},
3000);

});

Got it!