Last active
February 26, 2023 11:41
-
-
Save brew-martin/5281323 to your computer and use it in GitHub Desktop.
Small and simple cookie banner, uses a bit of PHP, JavaScript/jQuery and some CSS for styling the banner.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if(!isset($_COOKIE["comply_cookie"])) { ?> | |
<div id="cookies"> | |
<p>Our website uses cookies. By continuing we assume your permission to deploy cookies, as detailed in our <a href="yourPolicy">privacy policy</a>. | |
<span class="cookie-accept" title="Okay, close"><img src="img/close.png" alt="Close"/></span></p> | |
</div> | |
<?php } ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('.cookie-accept').click(function () { //on click event | |
days = 182; //number of days to keep the cookie | |
myDate = new Date(); | |
myDate.setTime(myDate.getTime()+(days*24*60*60*1000)); | |
document.cookie = "comply_cookie = comply_yes; expires = " + myDate.toGMTString(); //creates the cookie: name|value|expiry | |
$("#cookies").slideUp("slow"); //jquery to slide it up | |
}); | |
//--- | |
document.getElementById("cookie-accept").onclick = function(e) { | |
days = 182; //number of days to keep the cookie | |
myDate = new Date(); | |
myDate.setTime(myDate.getTime()+(days*24*60*60*1000)); | |
document.cookie = "comply_cookie = comply_yes; expires = " + myDate.toGMTString(); //creates the cookie: name|value|expiry | |
document.getElementById("cookies").parentNode.removeChild(elem); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#cookies { | |
width: 100%; | |
margin: 0; | |
padding: 0.5em 10%; | |
background: rgba(86,86,86,0.95); | |
border-bottom: solid 1px rgb(225,225,225); | |
} | |
#cookies p { | |
font-family: sans-serif; | |
font-size: 14px; | |
font-weight: 700; | |
letter-spacing: 1px; | |
text-shadow: 0 -1px 0 rgba(0,0,0,0.35); | |
text-align: center; | |
color: rgb(255,255,250); | |
margin: 4px; | |
z-index: 999; | |
} | |
#cookies .cookie-accept { | |
padding-left: 10px; | |
cursor: pointer; | |
display: inline; | |
color: rgb(255,255,250); | |
text-shadow: 0 -1px 0 rgba(0,0,0,0.35); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment