0

Why does on my page http://omt-serwis.pl cookie is set (the cookie popup does not appear again GLOBALLY on the whole page) only when I click cookie checkmark on the Home Page (http://omt-serwis.pl), but not on the subpages for instance http://omt-serwis.pl/kontakt/?

This is my code:

HTML:

<div class="june2018cookies">
    <p class="info">Strona korzysta z plików cookies w celu realizacji usług. Możesz określić warunki przechowywania lub dostępu do plików cookies w Twojej przeglądarce.<br> 
    <a href="http://omt-serwis.pl/informacja-o-ciasteczkach/" style="color:#fff;font-weight:900;text-decoration:none;font-size:16px;display:inline-block;padding:10px 0;">Dowiedz się więcej.</a></p>
    <div class=""></div>
    <i class="far fa-check-circle june2018cookies-close"></i>
</div>

JS:

var PopUpCookie = getCookie("MyPopUpCookie");
if (PopUpCookie == '') {

    setTimeout(june2018cookie, 0);
    } else {

    }


jQuery('.june2018cookies-close').on('click', function () {
    setCookie("MyPopUpCookie");

    jQuery('.june2018cookies').addClass('offsetright');

});

function setCookie(cname, cvalue) {
    var d = new Date();
    d.setTime(d.getTime() + (5*24*60*60*1000)); /* 2 days */
    var expires = "expires=" + d.toUTCString();
    document.cookie = cname + "=" + cvalue + "; " + expires;
}

function getCookie(cname) {
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1);
        if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
    }
    return "";
}


function june2018cookie() {


        jQuery('.june2018cookies').animate({
            "right": "+=350px"
        });

        jQuery('.june2018cookies').removeClass('offsetright');
}
Taplar
  • 24,788
  • 4
  • 22
  • 35
  • Possible duplicate of [How do I set path while saving a cookie value in JavaScript?](https://stackoverflow.com/questions/7551113/how-do-i-set-path-while-saving-a-cookie-value-in-javascript) – Taplar Jun 01 '18 at 17:52
  • 1
    You need to explicitly set the path to `/` so that it will effect your entire domain. If you set it on a sub-page of the site, the path will not be `/` by default. – Taplar Jun 01 '18 at 17:53

0 Answers0