How to Use JavaScript to Display a Custom Banner After Cookie Consent


Obtaining user consent for processing their data is a crucial aspect of compliance with data privacy regulations, such as GDPR and CCPA. To enhance user experience, you might want to display a customizable banner on your website after the user has provided consent via a cookie banner. This article will guide you through the use of a JavaScript code snippet that displays a banner after the user has accepted cookie consent.

The JavaScript code for this functionality can be found in the file checkCookieConsentAndShowPopup.js on GitHub.

It’s a simple and versatile solution that allows you to show a banner with configurable content once the user has given their consent.

Getting Started

Before we delve into the code, let’s understand the purpose of this JavaScript code and its key components:


These variables determine the names of the cookies used to check if the user has accepted cookie consent and if the banner has been displayed. You can adjust these names according to your requirements.


  • COOKIE_POPUP_CLASS is the CSS class name for the custom banner, which you can style to match your website’s design.
  • COOKIE_POPUP_LINK is the URL to which users will be redirected when they click the “Accept” button on the custom banner. You can customize this URL to suit your needs.

3. bannerContent Object

This object contains the content for your custom banner, including the title, text, and labels for the “Accept” and “Reject” buttons. You can personalize these elements to align with your website’s branding and message.


To integrate this code into your website to display a custom banner after cookie consent, follow these steps:

  1. Include the checkCookieConsentAndShowPopup.js script in your website’s HTML file.
<script src="path-to-checkCookieConsentAndShowPopup.js"></script>

2. Customize the variables in the JavaScript code to match your website’s requirements. Adjust COOKIE_NAME, COOKIE_POPUP, COOKIE_POPUP_CLASS, COOKIE_POPUP_LINK, and the content within the bannerContent object.

By following these steps, you can integrate this JavaScript code into your website to display a custom banner after users have given their cookie consent. The custom banner will only appear if users haven’t already provided consent. Remember to tailor the code to your specific website’s needs and styling to ensure a seamless user experience and compliance with data privacy regulations.

The code

This gist contains JavaScript code for displaying a customizable banner on a website after the user has accepted cookie consent.


Post navigation

You might be interested in...

No comments yet, be the first!


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