Simple Cross-Browser Cookie Consent Plugin In Vanilla JavaScript | cookieconsent

Cookie Consent is a lightweight, gdpr compliant cookie consent plugin written in plain javascript. An “all in one” solution that also allows you to write your own cookie policy inside without the need for a dedicated page.

Available data-cc actions

Any button (or link) can use the custom data-cc attribute to perform a few actions without manually invoking the API methods.

Valid values:

  • c-settings: show settings modal
  • accept-all: accept all categories
  • accept-necessary: accept only categories marked as necessary/read-only (reject all)
  • accept-custom: accept currently selected categories inside the settings modal

Key features

  • Lightweight
  • Cross-browser support (IE8+)
  • Standalone (no external dependencies needed)
  • GDPR compliant
  • Support for multi-language
  • WAI-ARIA compliant
  • Allows you to define different cookie categories with an opt-in/out toggle
  • Allows you to define custom cookie tables if you want to clarify the cookies you use

Must Read: How to Create a Simple Cookie Banner Consent Using Bootstrap 4

Cross-Browser Cookie Consent Plugin Details

Post NameGDPR Cookie Consent Script
Author Nameorestbida
CategoryCookies, Popup Plugins
Official PageClick Here
Publish DateAugust 29, 2020
Last UpdateJuly 30, 2023
DownloadLink Below

How to make use of it:

1. Insert the JavaScript file cookieconsent.js into the HTML document.

<script src="./dist/cookieconsent.js"></script>

2. Initialize the library and show the cookie consent popup on the web page load.{
  "cc_autorun" : true,
  "cc_website_name" : "Web Code Flow",
  "cc_website_url" : "",       
  "cc_theme_css" : "./src/cookieconsent.css" // path to theme CSS

3. Customize the cookie consent popup with the next options.{

  // parent contianer
  cc_container : "body", 

  // auto language detection
  cc_auto_language: false,

  // or set language here
  cc_current_lang : "en",               
  cc_default_lang : "en",

  // auto display on page load
  cc_autorun: false, 

  // delay in ms
  cc_delay: 20,

  // website name
  cc_website_name : null,   

  // website URL
  cc_website_url: null,

  // enable console log
  cc_enable_verbose: true, 
  // 30 days
  cc_cookie_expires : 30, 
  // cookie name
  cc_cookie_name: "cc_cookie",

  // theme css
  cc_theme_css: "/public/assets/css/cookieconsent.css"

4. API strategies.

// show the cookie consent popup;

// hide the cookie consent popup

// clear cookies

All configuration options

Below is a table that sums up all of the available options (must be passed to the .run() method).

Must Read: A Modal Dialog Bootstrap Cookie Banner Consent Settings and Framework

autorunbooleantrueIf enabled, show the cookie consent as soon as possible (otherwise you need to manually call the .show() method)
delaynumber0Number of milliseconds before showing the consent-modal
modestring‘opt-in’Accepted values:
– opt-in: scripts will not run unless consent is given (gdpr compliant)
– opt-out: scripts — that have categories set as enabled by default — will run without consent, until an explicit choice is made
cookie_expirationnumber182Number of days before the cookie expires (182 days = 6 months)
cookie_necessary_only_expirationnumberSpecify if you want to set a different number of days – before the cookie expires – when the user accepts only the necessary categories
cookie_pathstring“/”The path where the cookie will be set
cookie_domainstringlocation.hostnameSpecify your domain (will be grabbed by default) or a subdomain
cookie_same_sitestring“Lax”SameSite attribute
use_rfc_cookiebooleanfalseEnable if you want the value of the cookie to be RFC compliant
force_consentbooleanfalseEnable if you want to block page navigation until user action (check faq for a proper implementation)
revisionnumber0Specify this option to enable revisions. Check below for a proper usage
current_langstringSpecify one of the languages you have defined (can also be dynamic): 'en''de' …
auto_languagestringnullLanguage auto-detection strategy. Null to disable (default), "browser" to get the user’s browser language or “document” to read the value from <html lang=”…”> of the current page. If language is not defined => use specified current_lang
autoclear_cookiesbooleanfalseEnable if you want to automatically delete cookies when the user opts out of a specific category inside cookie settings
page_scriptsbooleanfalseEnable if you want to easily manage existing <script> tags. Check and manage third-party scripts
remove_cookie_tablesbooleanfalseEnable if you want to remove the HTML cookie tables (but still want to make use of autoclear_cookies)
hide_from_botsbooleantrueDisable if you want the plugin to run when a bot/crawler/web driver is detected
gui_optionsobjectCustomization option which allows choosing layout, position, and transition. Check layout options & customization
onAcceptfunctionThe method runs on:
1. the moment the cookie consent is accepted
2. after each page load (if cookie consent has already been accepted)
onChangefunctionMethod run whenever preferences are modified (and only if cookie consent has already been accepted)
onFirstActionfunctionMethod run only once when the user makes the initial choice (accept/reject)
languagesobjectCheck below for the configuration

See Demo And Download


Official Website(orestbida): Click Here

This superior jQuery/javascript plugin is developed by orestbida. For extra Advanced usage, please go to the official website.

Related Posts


Responsive Image Gallery Lightbox jQuery Plugin | VenoBox

VenoBox is a responsive jQuery modal window plugin suitable for images, embedded content, iFrames, Google Maps, Vimeo, and YouTube videos. The big difference compared to many other…


[Animation] Bootstrap Multi-Level Responsive Dropdown Menu

Bootstrap-based multi-level dropdown navigation menu with cool animations. The dropdown on Hover is a jQuery plugin used to create Bootstrap multi-level scroll-triggered dropdown menus with CSS3 animations…


Google Translate Dropdown Customize With Country Flag | GT API

Flag google translates jQuery text that takes advantage of the Google Cloud Translation API to translate web content between languages by selecting a country from the dropdown…


HTML 5 File Input Optimized for Bootstrap 4.x./3.x with File Preview | Bootstrap Fileinput

bootstrap-fileinput is an improved HTML 5 file input  Bootstrap 5.x, 4.x and 3.x with file preview for different files, provides multiple selections, resumable section uploads, and more….


CSS Layout Components Horizontal/Vertical Stack | HStack and VStack

HStack and VStack in CSS – CSS layout components that (basically) stack anything horizontally and vertically. A pure CSS library that makes it easy to stack elements…


How to Add Floating Whatsapp Chat Button In HTML | venom-button

Venom Button is a very simple plugin for the jQuery floating WhatsApp button. Adds a floating button to your site that calls WhatsApp Click to Chat API. It will automatically start the WhatsApp…

Leave a Reply

Your email address will not be published. Required fields are marked *