Hello everyone, how are you?
I need help with an click event...
I included an HTML modal and need to control its closing and save a variable on localstorage so it doesn't show again after user interaction.
I created the code and tested on Codepen and works fine, but when I try on growthbook nothing happens... any ideas?
Here is the code:
Copy code
document.addEventListener("DOMContentLoaded", function () {
// Verifica se a modal já foi exibida
if (!localStorage.getItem("paymentModalShown")) {
showModal();
}
// Função para exibir a modal
function showModal() {
const modal = document.getElementById("paymentModal");
modal.style.display = "flex";
localStorage.setItem("paymentModalShown", "true"); // Salva no localStorage
}
// Fecha a modal quando o "X" é clicado ou quando a área fora da modal é clicada
const closeButton = document.querySelector(".close-btn");
const modal = document.getElementById("paymentModal");
closeButton.addEventListener("click", closeModal);
modal.addEventListener("click", function (event) {
if (event.target === modal) {
closeModal();
}
});
// Função para fechar a modal
function closeModal() {
const modal = document.getElementById("paymentModal");
localStorage.setItem("paymentModalShown", "true"); // Salva no localStorage
modal.style.display = "none";
}
});
f
fresh-football-47124
11/29/2024, 6:07 AM
How is this integrating with GrowthBook?
fresh-football-47124
11/29/2024, 6:09 AM
you're loading this JS via GrowthBook?
d
dry-market-38093
11/29/2024, 6:28 PM
Yes, I put them on visual editor on the JS tab
f
fresh-football-47124
11/29/2024, 6:29 PM
ah, well, you're waiting for the "DOMContentLoaded" event, which probably already happened