Skip to content

Instantly share code, notes, and snippets.

@leecrossley
Created July 18, 2012 14:03
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 leecrossley/3136382 to your computer and use it in GitHub Desktop.
Save leecrossley/3136382 to your computer and use it in GitHub Desktop.
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