0

I created a cookie alert in bootstrap 4. I also wrote a javascript code that will close this alert when pressed.

How can I make sure that this window does not appear if someone closed it once?

$(document).ready(function() {
  $("button.close").click(function() {
    $(".alert").hide();
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="alert alert-dismissible alert-danger cookies-notification" role="alert" style="margin-top: 20px;">
  <div class="container">
    <button type="button" class="close" data-dismiss="cookies-notification">
        <span aria-hidden="true">×</span>
        <span class="sr-only">Close</span>
      </button>
    <p style="font-size: 13px;">Ta strona korzysta z cookies. Korzystając z tej strony zgadzasz się na korzystanie z cookies zgodnie z ustawieniami twojej przeglądarki.</p>
  </div>
</div>
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
FSp1337
  • 11
  • 2
  • 4
    Ironically enough, use a cookie. – Rory McCrossan May 31 '18 at 07:19
  • 2
    Depends on what you mean by *"[...] if someone closed it once"*. Once per user account: maintain state on the server. Once per browser environment: maintain state in a cookie (as long as cookies are not cleared or don't expire). Once per view of the page: maintain state in a variable. – Robby Cornelissen May 31 '18 at 07:20
  • I do not want the window to appear again after closing. – FSp1337 May 31 '18 at 07:21
  • 1
    You could also use localStorage assuming you're happy to support IE8 and higher: https://stackoverflow.com/questions/40192296/when-a-user-closes-a-div-hide-that-div-on-all-site-pages – Rory McCrossan May 31 '18 at 07:23

0 Answers0