Pop-up Lightbox everyday once!

Hey,
Please help me! How to display lightbox only once everyday to each user. I mean everyday lightbox appeas once! I don’t want to put in local storage as it will display only once but I want to display lightbox everyday one time to user! Please provide me with code as I don’t know coding. I hope for reply.

Thanking You,
Dev Vora.

1 Like

Can someone reply plz???

1 Like

Hi,
I think the best solution is, when the popup is displayed, save today’s date to local storage. Then, every time the page is loaded, check local storage for the value. If it’s today - don’t show the popup, if it’s a different date - display it and save today’s date again, and so on…

The code can look something like:

import wixWindow from 'wix-window';
import {local} from 'wix-storage';

$w.onReady(function () {
    let today = new Date().toDateString();
    let popupDate = local.getItem('popupDate');

    if( popupDate !== today) {
        wixWindow.openLightbox("<LightboxName>"); //change to the actual lightbox name
        local.setItem('popupDate', today);
    }
});
3 Likes

Thank you very much!
You solved my big problem!
I appreciate you help.
thanks!!!

1 Like

Hi, I have a follow-up question:

  1. Where should I paste the code? under page or site code?
  2. I used this code, but everytime I refresh the website, it still pop-up the lightbox.

Thanks,
Adam

1 Like

You have to add on page code where you want to show it!
And make sure automatically display lightboxes is set to off.

2 Likes

Thank you!

I made sure that the automatically display lightbox is off. However it still doesn’t work:

  1. How do I control on which page the pop-up will appear on?
  2. I have tried to do it, and it the lightbox didn’t show u at all.

Thank you!

Can someone please answer me? I really need to know how to do that!

You have to paste code use on page on which you want lightbox to show! Not on lightbox code page!

1 Like

Hey Ohad - I’m looking to do a similar thing with a lightbox, but have it only appear once every month (or every 30 days, whichever is easiest) rather than once daily… is there a way to do that with Wix Code?

@admin75437 you need to calculate the date difference between the two dates:
taken from: javascript - How to calculate number of days between two dates? - Stack Overflow

function parseDate(str) {
var mdy = str.split(‘/’)
return new Date(mdy[2], mdy[0]-1, mdy[1])
}

function datediff(first, second) {
// Take the difference between the dates and divide by milliseconds per day.
// Round to nearest whole number to deal with DST.
return Math.round((second-first)/(10006060*24))
}

datediff(parseDate(popupDate), parseDate(today))

Thank you @ohad-laufer , that’s great!

My technical know-how is super basic - how and where should I add this to the existing site code on Wix, or combine it with the example you provided for Dev Vora in October 2017?

Thanks again, I really appreciate your support :clap:

did you find an answer?