-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
19 lines (16 loc) · 907 Bytes
/
Copy pathscript.js
File metadata and controls
19 lines (16 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const cookieBox = document.querySelector(".wrapper"),
acceptBtn = cookieBox.querySelector(".buttons button");
acceptBtn.onclick = ()=>{
// setting cookie for 1 month , after 1 month cookie will be expired automatically
document.cookie = "CookieBy=PoojaMulik; max-age="+60*60*24*30;
if(document.cookie){
// if the above cookie set
cookieBox.classList.add("hide"); //hide cookie box once cookie set
}else{
alert("cookie can't be set !"); //if cookie can't be set the alert an error
}
}
//let's hide the cookie box if cookie is set and not expired
let checkCookie = document.cookie.indexOf("CookieBy=PoojaMulik"); //checking our set cookie
//if the given string not found in the all cookies then it'll return -1 and we'll show the box if it return -1 otherwise hide the box
checkCookie != -1 ? cookieBox.classList.add("hide") : cookieBox.classList.remove("hide");