To ensure your sign-up form modal on Webflow only appears once per user session, you can use cookies to track user interaction with the modal. Here's how you can set this up:
<head> Section: Place a JavaScript snippet to check for a cookie and set it if not present.
document.addEventListener("DOMContentLoaded", function() {
function setCookie(name, value, days) {
var expires = "";
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + (value || "") + expires + "; path=/";
}
function getCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return null;
}
if (!getCookie('modalDisplayed')) {
// Display your modal here
setCookie('modalDisplayed', 'true', 1); // 1-day expiration
}
// Assume `modalElement` is defined somewhere with your modal
document.querySelector('#your-modal-id').addEventListener('click', function() {
setCookie('modalDisplayed', 'true', 1);
// Close the modal
});
});
To create a modal that appears only once on Webflow's homepage, use JavaScript to set a cookie based on user interaction (modal closure or form submission). Apply the code in Webflow’s custom code editor in the respective page settings and ensure the cookie logic aligns with your modal triggers.