Skip to content

Instantly share code, notes, and snippets.

@bavington
Last active May 17, 2022 06:22
Show Gist options
  • Star 30 You must be signed in to star a gist
  • Fork 33 You must be signed in to fork a gist
  • Save bavington/6727776 to your computer and use it in GitHub Desktop.
Save bavington/6727776 to your computer and use it in GitHub Desktop.
Simple EU Cookie Law Banner JavaScript
@Showcase-Joz
Copy link

thanks a lot, smashing help guys ;)

@YoannLeGoff
Copy link

Hi,
I've created a little fork of this one, as I think it's more user friendly to create the cookie when the user click on "close" instead of pushing the cookie once the text is displayed...

If you implement that in next version let me know so i'll trash that fork.

Cheers.

@MPMachado
Copy link

Thanks for sharing. I implemented this solution, but I noticed that when I refresh, the banner is removed. It's a normal behaviour?

@maxmiko
Copy link

maxmiko commented May 23, 2018

Anybody could help, how to update this code? Because it is disappear on refresh?

@dogseven
Copy link

It disappears, as it should, because it is assumed that you have agreed to it. That's what's in the text. It will re-appear after 14 days. Visitors won't want to see it every time they visit the page.

To see it again, delete the domain cookies for this site.

Copy link

ghost commented Jul 24, 2018

Hi,
what should the following code do?
if(window.dropCookie){ document.cookie = name+"="+value+expires+"; path=/"; }
Can't find a dropCookie property on the window object.

Best regards.

@timgerhard
Copy link

You can use this css:

/* [COOKIE BANNER] */
#cookie-law {
    position: fixed;
    z-index: 99999;
    background: white;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
    text-align: center;
    padding: 30px 0;
    right: 0;
    bottom: 0;
    left: 0;
}

#cookie-law p {
    margin: 0;
}

.close-cookie-banner span {
    position: absolute;
    top: 0;
    color: black;
    font-size: 25px;
}
/* [/COOKIE BANNER] */

@rosell-dk
Copy link

I created a fork which does not pollute the global namespace.
Also, it per default requires a click to make the banner stay away, but can easily be modified to only show once in a while, like this.

@bluefirex
Copy link

bluefirex commented Dec 4, 2019

For future Googlers: This script is NOT legally valid anymore.
https://www.reuters.com/article/us-eu-court-cookies/internet-users-must-actively-consent-to-use-of-cookies-eu-court-rules-idUSKBN1WG3NF

[...] cookie consent must be specific and explicit and that clicking a button to participate in a game or browsing a website, and through that allowing cookies, was not enough.

@cgowez
Copy link

cgowez commented Sep 2, 2020

Thanks @bavington and @timgerhard, this is simple and useful. I did a minor change as some people said, refreshing the page without closing the banner, it will just disappear, when createCookie function is called I create the cookie with a different value let's say "off" so if you reload the page function checkCookie looks for specific value, since it is different it will display the banner again when the user clicks to close the banner function removeMe is invoked so there I update the cookie value to "on".

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment