arifix
arifix

Reputation: 750

Cookie not stored on domain root

Live site- http://chitrchatr.com

I successfully add setCookie function on exit button & another link. So, if anyone close popup or click on that link then cookie will be stored & popup never appears for him/her.

It works perfectly, but cookie is not stored on domain root. So, if anyone close popup/click on subscribe link then cookie stored by following page url path, it appears again when anyone go to another page.

Any idea what is the problem of my code-

<script type="text/javascript">

        function setCookie(c_name,value,exdays)
        {
        var exdate=new Date();
        exdate.setDate(exdate.getDate() + exdays);
        var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
        document.cookie=c_name + "=" + c_value + "path=/";
        }

        function getCookie(c_name)
        {
        var c_value = document.cookie;
        var c_start = c_value.indexOf(" " + c_name + "=");
        if (c_start == -1)
          {
          c_start = c_value.indexOf(c_name + "=");
          }
        if (c_start == -1)
          {
          c_value = null;
          }
        else
          {
          c_start = c_value.indexOf("=", c_start) + 1;
          var c_end = c_value.indexOf(";", c_start);
          if (c_end == -1)
          {
        c_end = c_value.length;
        }
        c_value = unescape(c_value.substring(c_start,c_end));
        }
        return c_value;
        }


        if(getCookie('abc')=="def" && document.getElementById('popupBox'))
        document.getElementById('popupBox').style.display='none';
</script>

Upvotes: 0

Views: 146

Answers (1)

Fabio Beltramini
Fabio Beltramini

Reputation: 2511

You are missing a semicolon between your cookie value and your path:

"=" + c_value + "path=/";

"=" + c_value + ";path=/";

Upvotes: 1

Related Questions