Javascript to check if cookie exists in PrestaShop

Dear, I need insert javascript code into your module html box pro. I need verify if cookie, "cokiebar" is valid, (not expired) and the value. Then if is valid and value is "hide" execute this code: Is possible with your module with javascript ? can you help me? Thank very much, Massimo from italy

Hello
module 'html box pro' allows to use javascript code.
With Javascript you can check if cookie exists or what is the value of cookie (stored string in cookie).
in context of your case (cookie name is 'cokiebar') you can use code like:
<script>
function getCookie(cname) {
  var name = cname + "=";
  var decodedCookie = decodeURIComponent(document.cookie);
  var ca = decodedCookie.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 "";
} if (getCookie('cokiebar') == 'hide') { // execute something here }
</script>
Javascript to check if cookie exists in PrestaShop Javascript to check if cookie exists in PrestaShop Reviewed by VEKIA on Wednesday, January 09, 2019 Rating: 5

No comments