I am trying to make the website check if cookieOk variable is true, then remove the cookie banner if it comes out as true, so that it can apply to all the pages on the site. For some reason, it removes the cookie banner without me clicking "OK".
I checked in Inspect and cookieOk is already set to true, which also explains why it's not showing the banner for me to click "OK".
How can I set the cookieOk variable to "true" only after I click "OK"?
I am also very new to the JavaScript language so please spare me if I have any errors in my code.
Here's the code if you want to test.
function disappearObject1() {
var remove = document.getElementById("cookie-banner");
remove.remove();
var cookieOk = true;
}
if (cookieOk = true) {
var dis = document.getElementById("cookie-banner");
dis.remove();
}
.cookie-banner {
background-color: #226da3;
color: white;
font-family: "Raleway", "Poppins", sans-serif;
padding-top: 10px;
text-align: center;
width: 100%;
position: fixed;
bottom: 0;
}
.cookie-btn {
border-radius: 5px;
width: 50px;
border-color: white;
background-color: white;
cursor: pointer;
border-width: 1px;
color: #226da3;
display: inline-block;
position: relative;
text-decoration: none;
border: none;
font-family: "Raleway", "Poppins", sans-serif;
font-weight: 1200;
}
<footer>
<div class="gone" id="gone">
<div class="cookie-banner" id="cookie-banner">
<p class="p1"><b>This website uses cookies to improve user experience.</b></p>
<button type="button" onclick="disappearObject1()" class="cookie-btn"><b>OK</b></button>
</div>
</div>
</footer>
Aucun commentaire:
Enregistrer un commentaire