Minimal Cookie Consent Popup In JavaScript – PureCookie

Category: Javascript | March 28, 2019
Views Total:33,181 views
Official Page:Go to website
Last Update:March 28, 2019


Minimal Cookie Consent Popup In JavaScript – PureCookie


PureCookie is a small JavaScript library that displays an elegant cookie consent popup to ask the user to accept/reject cookies.

How to use it:

Download and import the PureCookie’s JavaScript & CSS files into your document. That’s it.

<link rel="stylesheet" href="purecookie.css"/>
<script src="purecookie.js"></script>

Config the cookie consent popup in the purecookie.js.

// popup title
var purecookieTitle = "Cookies."; 
// popup content
var purecookieDesc = "By using this website, you automatically accept that we use cookies.";
// policy link
var purecookieLink = '<a href="cookie-policy.html" target="_blank">What for?</a>'; 
// button text
var purecookieButton = "Understood";

You Might Be Interested In:

11 thoughts on “Minimal Cookie Consent Popup In JavaScript – PureCookie

  1. AlbanPatault


    Thanks for this stuff, realy helpful!

    A small addition to avoid breaking all js in your page :

    Replace at line 62 in purecookie.js

    document.body.innerHTML += “”


    var cookieDiv = document.createElement(‘div’); = ‘menu’;
    cookieDiv.innerHTML = ””;

    The use of body.innerHTML += rewrites the whole document, and breaks your js.
    If there are any event listeners bound to elements in the document, those are gone too because the elements were destroyed and replaced with identical-looking ones.

    1. Pedro Knigge

      I just replace body.innerHTML by: document.getElementById(“aca-va-el-pop-up”).innerHTML
      and put some div with and ID in the body:
      Now just put the content in that div without break everything.

      Full code:
      function cookieConsent() {
      if (!getCookie(‘purecookieDismiss’)) {
      document.getElementById(“aca-va-el-pop-up”).innerHTML += ‘‘ + purecookieTitle + ‘‘ + purecookieDesc + ‘ ‘ + purecookieLink + ‘‘ + purecookieButton + ‘‘;

  2. dsm

    I tried your change in the script and it works very well, before that I had a problem with the search engine and reCAPTCHA v2


Leave a Reply