Custom Functions

How to make custom functions of the banner?

Written by NelsonLast update 28 days ago

In some cases, you might need to be able to control your Cookie Banner behavior programmatically or read the current state of the user consent. CookieScript provides a set of functions that can be utilized to customize cookie controls programmatically.

These functions are accessible via CookieScript.instance once it is initialized.

List of CookieScript functions and their description






Forces the Cookie Banner to appear.



Forces the Cookie Banner to close



Returns the current state of the user's consent as an object with two properties:

action: 'accept' | 'reject' ;

categories: ['strict', 'performance', 'targeting', 'functionality', 'unclassified'].



Returns an array of the available cookie categories as an array of the following cookie types: 

['strict', 'performance', 'targeting', 'functionality', 'unclassified'].



Manually accepts all cookies.



Manually rejects all cookies except for the strictly necessary.


String array categories

Manually accepts some of the cookie categories passed as its parameter:

CookieScript.instance.acceptAction(['performance', 'targeting']).

Show / Hide Cookie Banner

CookieScript banner can be shown or hidden with the following functions: 

This would be equivalent to making the banner to popup by clicking on the cookie badge or closing the banner by clicking on the close button.

Get the current consent state

The current cookie choice of the user can be read by calling this function: 


The function returns an object with 2 properties:

    action: 'accept' | 'reject',
    categories: ['strict', 'performance', 'targeting', 'functionality', 'unclassified']

The action property can be either accept  or reject .

The categories property is an array of what the user has agreed to and may contain any of the following categories: [ strictperformancetargetingfunctionalityunclassified ].




Means that the user has agreed to one or more cookie categories. List of accepted categories can be found in the  category  property.


Means the user rejected all cookies. In this case  categories  property still stores  strict  cookie category since it cannot be rejected.

Get available categories

Some websites do not require nor do they use all the cookie categories mentioned above. The cookie types that are currently available for the user to choose from can be seen using the following function:


The function returns an array of available category keys:

let categories = CookieScript.instance.categories();
// the variable categories is going to look
// somewhat like this:
// ['performance', 'targeting', 'functionality']

Accept / Reject cookie policy

You can accept or reject the cookie policy with built-in functions. This might be handy if you want to place a link asking the user to accept cookies before some functionality will be available. 

Accept all cookies

All cookies can be accepted with the following function: 


This is the same as clicking Accept all button.

Reject all cookies

All cookies (except strictly necessary) can be rejected with this function: 


This is the same as clicking Reject all button. 

Accept some cookies

In case cookie categories are enabled, they can be accepted programmatically using this function:


The function requires a parameter with a list of the categories to be accepted, like in this example:

var categories = ['performance', 'targeting', 'functionality', 'unclassified'] CookieScript.instance.acceptAction(categories)

Code examples

How to stop showing CookieScript cookie banner?

If there is a problem that some website editors always show CookieScript cookie banner, you can stop showing it with this code. The code is also useful if your banner shows up in the iframe which loads under the same domain and you don't need to show the banner in that iframe.

<script type="text/javascript" 

A link that makes the Cookie Banner to appear:

<a href="">show popup</a>

This is equivalent to clicking the CookieScript badge.

A link that lets the user to accept all cookies:

<a href="javascript:CookieScript.instance.acceptAllAction()">
    By continuing you are accepting all cookies.

A link that lets the user to accept some categories

<a href="javascript:CookieScript.instance.acceptAction(['performance', 'targeting'])">

CookieScript events

CookieScript also provides a variety of events to listen to Cookie Banner's actions. We have created a detailed explanation of how custom events work.

Did this answer your question?