Home » Javascript » Cookie that stores that my cookiepopup have been accepted when “acccept”-button is pressed

Cookie that stores that my cookiepopup have been accepted when “acccept”-button is pressed

Posted by: admin August 12, 2018 Leave a comment

Questions:

My button that removes the div once clicked. How do I link this to a cookie that stores info that this div already has been displayed and shouldn’t show. I’m trying to do this without jquery.

HTML

<button class="button"><a id="cookie-accept" class="cookie-accept" onclick="cookieDestroy()">i accept</a> </button>

JS – this destroys the div onclick.

function cookieDestroy() { var x = document.getElementById("banner-cookie"); x.remove()}

Cookie-js – w3schools setCookie

function setCookie(cname,cvalue,exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires=" + d.toGMTString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";

}

Answers: