Creating a one-time popup

Hello! I was following this wix article to make a light box only show once per user. The article URL: https://support.wix.com/en/article/corvid-tutorial-creating-a-one-time-popup . The code doesn’t seem to work fo me.

import {local} from 'wix-storage';
import wixWindow from 'wix-window';
$w.onReady(function () {
if(!local.getItem("firstTimePopupShown")) {
    wixWindow.openLightbox("photo");
    local.setItem("firstTimePopupShown","yes");
}
});

“photo” in the 5th line is the name of my light box.
I would really appreciate it if someone could point out which bit needs fixing.
Arthur😀

Your code looks fine.
Be sure to test it on your live site and not on preview mode.
It might not work if your browser is in incognito/private mode.

No, I was testing it on my live site. I also tried it on both safari and Firefox. You will see the popup but when you reload the page, you still get the popup.
~Thanks~
Arthur

Hey Arthur,

You might find this post helpful.

They were having the same issue as you and managed to resolve it.

Hope this helps!

Dara | Corvid Tea,

Make sure you disabled the automatic opening of the lightbox (it’s on the lightbox settings).

Hello. I tried that code on the post but the light box is still showing. I made shore that the light box doesn’t automatically often when the page loads. I set a link for it. I am still seeing multiple times. Here is my code:

import wixWindow from 'wix-window';
import { local } from 'wix-storage';
$w.onReady(function () {
let isFirstTime = local.getItem("firstTimePopupShown");
if(!isFirstTime) {
wixWindow.openLightBox("photo")
.then((data) => {
let recevedData = data;
local.setItem("firstTimePopupShown", true);
});
} else {
    console.log("Not first time");
}
});

I would really appreciate it if you could spot witch bit needs fixing.
~Thanks for all the help~
Arthur

First of all, you have a spelling error.
Instead of:

wixWindow.openLightBox("photo")

it should be:

wixWindow.openLightbox("photo")

Second, you put the local.setItem in the .then() part which means that it’ll keep showing the popup unless the user closed the popup using code.
You should put the local.setItem() outside the .then() or even in the lightbox code.

Third, the second argument in the local.setItem() should be a string and not a Boolean.

lol like yeh you’r right. Thanks!

It still won’t work. Maybe I have to just give-up. Also, wix should update their article about this. Then maybe I can do it too.:grinning:

Hi J.D., i’m having the same issue. Would you mind posting the correct code adjusting for the corrections you made when you replied to Arthur? It would be of tremendous help as i’m not familiar with coding.