javascriptcookiescookieconsent

How do I get the cookie consent script to work?


I have implemented a cookie consent script by Creare: https://www.creare.co.uk/blog/js/js-eu-cookie-law-banner

in my website: https://www.drive-tastic.co.uk/

but I cannot get it to work.

Can anyone help please?


Solution

  • The body tag of your website has an onload handler:

    <body onload="MM_preloadImages('images/fb-icon-hover.png')">
    

    The cookie script you've downloaded also has an onload handler:

    window.onload = function(){
        if(checkCookie(window.cookieName) != window.cookieValue){
            createDiv(); 
        }
    }
    

    Try replacing it with the following instead:

    document.addEventListener('DOMContentLoaded', function() {
        if(checkCookie(window.cookieName) != window.cookieValue){
            createDiv(); 
        }
    });
    

    Hope that helps!