Skip to content

Instantly share code, notes, and snippets.

@BananaAcid
Last active May 24, 2018 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BananaAcid/d46e353b11e6b545a7e22efcdd9bef7a to your computer and use it in GitHub Desktop.
Save BananaAcid/d46e353b11e6b545a7e22efcdd9bef7a to your computer and use it in GitHub Desktop.
cookie msg - infoo popup in js/html only + jquery
<!-- inlcude/reference jquery -->
<style>
#cookieMsgContainer {display: none;}
#cookieMsg + section {transition: .5s ease-out; z-index: 2000;}
#cookieMsg:not(:checked) + section {transform: translateY(100%);}
</style>
<input type="checkbox" checked id="cookieMsg" style="display: none" />
<section id="cookieMsgContainer" style="position: fixed; bottom: 0; left: 0; background: black; text-align: left; color: white; width: 100vw; padding: 25px; font-family: sans-serif;">
<article style="max-width: 600px; margin: auto;">
<p><strong>Diese Seite verwendet Cookies</strong></p>
<ul>
<li>... um die Navigation auf dieser Seite zu ermöglichen <small>(Session-Cookie)</small>.</li>
<li>... um den Traffic auf dieser Website zu analysieren. Informationen zu Ihrer Nutzung auf dieser Website werden anonym an Google übermittelt.</li>
</ul>
<p>
<a style="color: #08c" href="/datenschutz/">Weitere Details</a>
</p>
<p style="text-align: center;">
<label for="cookieMsg" style="padding: 10px; background: #08c; color: white; max-width: 100px; text-align: center; cursor: pointer;">Akzeptieren</label>
</p>
</article>
</section>
<script>
(function($) {
$(function() {
if (cookie.get('cookieMsgSeen') !== 'yes')
{
cookie.set('cookieMsgSeen', 'yes', 365);
$('#cookieMsgContainer').css('display', 'block');
}
});
})(jQuery);
</script>
(function() {
var cookie = function() {};
cookie.set = function cookieSet(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/;domain=." + document.location.hostname;
}
cookie.get = function cookieGet(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return undefined;
}
window.cookie = cookie;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment