🍪🍪🍪
This commit is contained in:
parent
079c120312
commit
901bedc073
2 changed files with 64 additions and 2 deletions
14
index.html
14
index.html
|
@ -12,7 +12,7 @@
|
|||
|
||||
<body>
|
||||
<header class="page-header" role="banner">
|
||||
<h1 class="project-name" style="font-family: DarkNewRoman;""> Array in a matriX
|
||||
<h1 class="project-name" style="font-family: DarkNewRoman;"> Array in a matriX
|
||||
</h1>
|
||||
<h3 class=" project-tagline">Welcome to the abyss.</h3>
|
||||
</header>
|
||||
|
@ -24,6 +24,16 @@
|
|||
<a href="/index/games/" class="btn">Games</a>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<footer style="font-family: 'Montserrat', sans-serif;">
|
||||
<div id="cookiePopup">
|
||||
<h3>Can I have a cookie, please? (^ω^)</h3>
|
||||
<button class="btn" id="acceptCookie">Give cookie 🍪</button>
|
||||
</footer>
|
||||
<script src="script/cookies.js"></script>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
52
script/cookies.js
Normal file
52
script/cookies.js
Normal file
|
@ -0,0 +1,52 @@
|
|||
// set cookie according to you
|
||||
var cookieName = "ConsentCookie";
|
||||
var cookieValue = "Consent?";
|
||||
var cookieExpireDays = 7;
|
||||
|
||||
// when users click accept button
|
||||
let acceptCookie = document.getElementById("acceptCookie");
|
||||
acceptCookie.onclick = function () {
|
||||
createCookie(cookieName, cookieValue, cookieExpireDays);
|
||||
}
|
||||
|
||||
// function to set cookie in web browser
|
||||
let createCookie = function (cookieName, cookieValue, cookieExpireDays) {
|
||||
let currentDate = new Date();
|
||||
currentDate.setTime(currentDate.getTime() + (cookieExpireDays * 24 * 60 * 60 * 1000));
|
||||
let expires = "expires=" + currentDate.toGMTString();
|
||||
document.cookie = cookieName + "=" + cookieValue + ";" + expires + ";path=/";
|
||||
if (document.cookie) {
|
||||
document.getElementById("cookiePopup").style.display = "none";
|
||||
} else {
|
||||
alert("Unable to set cookie. Please allow all cookies site from cookie setting of your browser");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// get cookie from the web browser
|
||||
let getCookie = function (cookieName) {
|
||||
let name = cookieName + "=";
|
||||
let decodedCookie = decodeURIComponent(document.cookie);
|
||||
let ca = decodedCookie.split(';');
|
||||
for (let i = 0; i < ca.length; i++) {
|
||||
let c = ca[i];
|
||||
while (c.charAt(0) == ' ') {
|
||||
c = c.substring(1);
|
||||
}
|
||||
if (c.indexOf(name) == 0) {
|
||||
return c.substring(name.length, c.length);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
// check cookie is set or not
|
||||
let checkCookie = function () {
|
||||
let check = getCookie(cookieName);
|
||||
if (check == "") {
|
||||
document.getElementById("cookiePopup").style.display = "block";
|
||||
} else {
|
||||
|
||||
document.getElementById("cookiePopup").style.display = "none";
|
||||
}
|
||||
}
|
||||
checkCookie();
|
Loading…
Add table
Reference in a new issue