0

I have cookie notice on my corporate website, which announces to new users that we are using cookies, however if the visitor presses a button, the dialog does not close and keeps showing to them. My html for cookie notice

<div id="cookie-warning">
  <img src="https://d32exi8v9av3ux.cloudfront.net/web/2018/05/17/37b039b/website/common/img/ic_cookie.svg">
  <p>We are using cookies to provide statistics that help us give you the best experience of our site. You can find out more by visiting our <a href="/cookies/">cookie policy</a>.<br>By continuing to use the site, you are agreeing to our use of cookies.</p>
  <a href="#" class="gotit">Got it</a>
</div>

        <script type="text/javascript">
    $("#cookie-warning .gotit").click(function (e) {
        e.preventDefault();
        $("#cookie-warning").remove();
        $.cookie("accepted_cookies", "1", { "expires": 365, "path": "/" });
    });

I guess the CSS doesn't really play any role here, so i won't include it. From my point of view, there seems to be everything OK, but just doesn't close, anybody could maybe lighten up some things for me?

  • For starters, your "expires" date is wrong. [Here](https://stackoverflow.com/questions/1830246/how-to-expire-a-cookie-in-30-minutes-using-jquery) for how to set it up properly. Of course, you wouldn't want to use 30 minutes but rather 365 days (525,600 minutes) – meyi May 22 '18 at 13:50
  • You should check, If there is a cookie called `accepted_cookies ` if there is, you should hide your cookie-warning div. I can't see that in your code – JiiB May 22 '18 at 13:56
  • Note that at least some ad blockers automatically hide elements with ID "cookie-warning". Mine does, at least. Made for some confusion as I tried running your code in a snippet... – Daniel Beck May 22 '18 at 13:57

1 Answers1

0

Maybe it is stupid though, but is this whole code snippet complete? If so, then there is closing </script> tag missing. I've tried your code and it works.

Bednic
  • 71
  • 1
  • 7