[ad_1]
I’m adding Cookies on the websites of the companies I work for, and I’ve come across a problem on some websites; when adding the cookie, it is displayed normally on the site, but when accepting and refreshing the page the message continues to appear, what could be causing this?
I checked that maybe it could be the version of JQuery I’m using (JQuery 1.7), but I updated the library and the error persists, can anyone help me?
JS Code:
function cookies(functions) {
const container = document.querySelector('.cookies-container');
const save = document.querySelector('.cookies-save');
if (!container || !save) return null;
const localPref = JSON.parse(window.localStorage.getItem('cookies-pref'));
if (localPref) activateFunctions(localPref);
function getFormPref() {
return [...document.querySelectorAll('[data-function]')]
.filter((el) => el.checked)
.map((el) => el.getAttribute('data-function'));
}
function activateFunctions(pref) {
pref.forEach((f) => functions[f]());
container.style.display = 'none';
window.localStorage.setItem('cookies-pref', JSON.stringify(pref));
}
function handleSave() {
const pref = getFormPref();
activateFunctions(pref);
}
save.addEventListener('click', handleSave);
}
function marketing() {
console.log('Função de marketing');
}
function analytics() {
console.log('Função de analytics');
}
cookies({
marketing,
analytics,
});
function fechar() {
document.getElementById('cookie').style.display = 'none';
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
PHP Code:
<div class="cookies-container" id="cookie">
<div class="cookies-content">
<div>
<p>
Este site ultiliza cookies e outras tecnologias semelhantes para
melhorar a sua experiência em nossa plataforma. Você aceita
a politica de privacidade?
</div>
<div class="cookies-pref">
<button class="cookies-save btn btn-warning">Sim</button>
<button onclick="fechar()" class="btn btn-light cookies-no" style="color: #000;">Não</button>
</div>
<div class="politica">
<a href="">Ver nossa política de privacidade?</a>
</div>
</div>
</div>
<!-- <?= $CAMINHO ?>/index.php?sessao=<?= verifica($sequencia . $politicaPrivacidade . $complemento); ?>&id=<?= $menuNossaCidade['id'] ?> -->
(I’m using jquery 1.7)
If anyone can help me, I’d appreciate it!
[ad_2]