Cookie Code don't work

hi, I did use this code for the cookie info:

<script>
// A $( document ).ready() block.
document.addEventListener("DOMContentLoaded", function() {
if (document.cookie.indexOf('visited=true') == -1){
// load the overlay
$('#modal-cookie').modal({show:true});

var year = 1000*60*60*24*365;
var expires = new Date((new Date()).valueOf() + year);
document.cookie = "visited=true;expires=" + expires.toUTCString();

}
}); 
</script>

Since 4.3 it doesn’t work anymore. Thanks for your support.

Ralf,
I use the same code.
Works here with Blocs 4.3.2-b2 and 4.3

Hi @RME

I have checked it on 4.3.1 and 4.3.2 and it also doesn´t work.
But for Cookie Message its not the best, because there is no Opt in or Opt out option. You need that option for example when you use maps and analytic tools. Other Modal Codes just work ( Snippet Site Pealco )

tom

Hi @RME

If your using Bootstrap 5 it won’t work as that code uses JQuery. Which is not loner used in BS.

Norm has included an export option to add it on export though. Make sure you tick the include JQuery box.

Ideally the JQuery part should be rewritten in pure JavaScript.

1 Like

Are you saying by pure meaning Vanilla script?

It’s just JavaScript really. People say vanilla or pure to highlight no JQuery dependencies.

1 Like

Ok, and what I have to do that the code is working? The cookie bric is ok but I can’t chance the fonts and other design elements. I would like to get my own modal for cookies.

Hey @RME

This should work for you. Basically the same, just the calling the modal is different in Bootstrap 5.

<script>
document.addEventListener("DOMContentLoaded", function() {
  if (document.cookie.indexOf('visited=true') == -1){
    var cookieModal = new bootstrap.Modal(document.getElementById('modal-cookie'));
   cookieModal.show();
   var year = 1000*60*60*24*365;
   var expires = new Date((new Date()).valueOf() + year);
   document.cookie = "visited=true;expires=" + expires.toUTCString();
 }
}); 
</script>

Reference Docs are here

4 Likes

Perfect @Malachiman. Thanks a lot.
It would be great to have these code in a bric for the cookies. :slight_smile:

3 Likes

Does this code work only with BS5?
As I told earlier the code I use works perfect with BS4.

I answer myself: yes it does.