Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
NICE Cookie Usage - shows a banner at the top of the page (once) if based in the EU.
(function ($) {
function setCookie(a, b, c) {
var d = new Date();
d.setDate(d.getDate() + c);
var e = escape(b) + ((c == null) ? "" : "; expires=" + d.toUTCString());
document.cookie = a + "=" + e;
}
function getCookie(a) {
var i, x, y, cookieArray = document.cookie.split(";");
for (i = 0; i < cookieArray.length; i++) {
x = cookieArray[i].substr(0, cookieArray[i].indexOf("="));
y = cookieArray[i].substr(cookieArray[i].indexOf("=") + 1);
x = x.replace(/^\s+|\s+$/g, "");
if (x == a) {
return unescape(y);
}
}
}
function performCheck() {
if (getCookie("shownMessage")){
return;
};
var timeZone = -new Date().getTimezoneOffset() / 60;
var loc = "";
switch (timeZone) {
case -1:
case -0:
case 0:
case 1:
case 2:
case 3:
case 3.5:
case 4:
case 4.5:
loc = "Europe";
break;
case 9:
loc = "Japan"
}
if (loc !== "Europe") {
return;
}
var bannerHtml = "<div class=\"niceCookieLaw\"><div class=\"niceCookieContainer\">"
+ "<p>This website uses cookies. By continuing to browse the site you are agreeing to our use of cookies.</p>"
+ "<a class=\"niceCookiesMore\" href=\"#\">Find out more</a>";
$("body").prepend(bannerHtml);
$(".niceCookieLaw").show();
}
performCheck();
setCookie("shownMessage", true, 365);
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment