A
A
alh_22016-01-09 08:39:22
JavaScript
alh_2, 2016-01-09 08:39:22

Safari doesn't save cookies, what's wrong?

I made cookies on js in order to save the city that the user selects on my site. Works everywhere except Safari, what's wrong? Here is the code itself:

function getCookie(name) {
      var cookie = " " + document.cookie;
      var search = " " + name + "=";
      var setStr = null;
      var offset = 0;
      var end = 0;
      if (cookie.length > 0) {
        offset = cookie.indexOf(search);
        if (offset != -1) {
          offset += search.length;
          end = cookie.indexOf(";", offset)
          if (end == -1) {
            end = cookie.length;
          }
          setStr = unescape(cookie.substring(offset, end));
        }
      }
      return(setStr);
    }
    var townb = getCookie('town');
if(townb !== "" && townb !== null && townb !== "null" && townb !== " " && townb !== 0 && townb !== "0") {
      $('.user-city-g').html('г. '+townb);
    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question