Hi,
I’m using the following code to show a pop up only if a cookie doesn’t exist. If it doesn’t, the pop-up shows and a cookie is added. This stops the pop showing again for the time stated (when the cookie expires).
src=“https://cdnjs.cloudflare.com/ajax/libs/js-cookie/2.2.1/js.cookie.min.js”
const delay = 3; // pop-up delay in seconds
const popupId = “pop-up-wrapper”; // pop-up Id name
$(document).ready(function() {
if (!Cookies.get(‘alert’)) {
setTimeout(function() {
document.getElementById(popupId).style.display = “flex”;
Cookies.set(‘alert’, true, { expires: 1 });
}, delay*1000);
}
});
This works perfectly.
But…I’m now trying to link this to the CMS. I have created a switch in the CMS which is called Is Pop-Up. When the switch is on, this content is then shown in the pop-up. I’ve set the limit to 1, just encase someone sets more than one item on.
Ideally, I would like 2 things to happen, but would settle with just the first.
- If no items have the switch on, then the pop up will not show (at present the pop up shows with an empty collection list).
2)To set the expiration date for the pop-up. I.e be able to set a number of days rather than the default.
I’ve tried all sorts of code, most commented out within the page settings, but I can’t seem to get it to work.
If anyone has any ideas or if this is possible that would be greatly apprecaited.
Here is my site Read-Only: Webflow - Freyja