// Function to set a cookie 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 to get a cookie 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) { // If the cookie is found, hide the popup document.getElementById("popup-banner").style.display = "none"; return c.substring(name.length, c.length); } } // If the cookie is not found, show the popup document.getElementById("popup-banner").style.display = "block"; return ""; } // Show the popup and set the cookie when the close button is clicked function closePop() { setCookie("shownPopup", "true", 30); // Cookie expires in 30 days document.getElementById("popup-banner").style.display = "none"; } // Run the function on page load window.onload = function() { // Dynamically add the popup HTML to the page var d1 = document.getElementsByTagName("BODY")[0]; d1.insertAdjacentHTML('beforeend', ` `); // After the popup HTML is added, check the cookie status getCookie("shownPopup"); };