Hi all,
We have created a popup for the acceptance of terms of use for professional investors (using Nikolai Bain’s Pop-up Modal), in addition to standard privacy cookies (using Finsweet Cookie Consent).
We are trying to achieve that when the ‘I Confirm’ button is clicked and this acceptance is stored in the cookies, the popup is closed and not displayed again to the user.
Any ideas?
Here is our site Read-Only: [LINK]
If anyone is looking for the code to do this:
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
document.addEventListener("DOMContentLoaded", function() {
var modalWrapper = document.getElementById("modalWrapper");
var confirmButton = document.getElementById("confirmButton");
var notConfirmButton = document.getElementById("notConfirmButton");
confirmButton.addEventListener('click', function() {
setCookie('termsAccepted', 'true', 365);
modalWrapper.style.display = 'none';
document.body.style.overflow = 'auto';
});
notConfirmButton.addEventListener('click', function() {
setCookie('termsAccepted', 'false', 365);
window.location.href = 'https://www.website.com/';
});
var termsAccepted = getCookie('termsAccepted');
if (termsAccepted == 'true') {
modalWrapper.style.display = 'none';
document.body.style.overflow = 'auto';
} else {
modalWrapper.style.display = 'flex';
document.body.style.overflow = 'hidden';
}
});
2 Likes