Cookie Constent Box | CodingNepal
This website use cookies to ensure you get the best experience on our website.
const cookieBox = document.querySelector(« .wrapper »),
acceptBtn = cookieBox.querySelector(« button »);
acceptBtn.onclick = ()=>{
//setting cookie for 1 month, after one month it’ll be expired automatically
document.cookie = « CookieBy=Oltrodox; max-age= »+60*60*24*30;
if(document.cookie){ //if cookie is set
cookieBox.classList.add(« hide »); //hide cookie box
}else{ //if cookie not set then alert an error
alert(« Cookie can’t be set! Please unblock this site from the cookie setting of your browser. »);
}
}
let checkCookie = document.cookie.indexOf(« CookieBy=Oltrodox »); //checking our cookie
//if cookie is set then hide the cookie box else show it
checkCookie != -1 ? cookieBox.classList.add(« hide ») : cookieBox.classList.remove(« hide »);