0

I have a setCookie and getCookie function in my code. They work perfectly fine in IE and FireFox but not in Chrome. Basically my script checks if certain checkboxes are checked and then based on the combination, stores a certain value in the cookie called "layer." I get an alert of the value stored in "layer," but it always comes out as "undefined" in Chrome. I've checked my settings, and I've allowed cookies and tried clearing them and accessing them again. BUT IT DOESN'T WORK! There's definitely nothing wrong in the functions themselves because they work fine in other browsers...it's just Chrome.

    function setCookie(cname,value,exdays)
               {
                    var d = new Date();
                    d.setTime(d.getTime() + (exdays*24*60*60*1000));
                    var expires = "expires="+d.toGMTString();
                    document.cookie = cname + "=" + value + "; " + exdays + "; ";    
               }

    function getCookie(c_name)
                {
                    var i,x,y,ARRcookies=document.cookie.split(";");
                    for (i=0;i<ARRcookies.length;i++)
                    {
                            x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
                            y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
                            x=x.replace(/^\s+|\s+$/g,"");
                            if (x==c_name)
                            {
                                return unescape(y);
                            }
                    }
                }

    var ch1 = document.getElementById("checkbox-h-2a").checked;
    var ch2 = document.getElementById("checkbox-h-2b").checked;
    var ch3 = document.getElementById("checkbox-h-2c").checked;

    if (ch1==true && ch2==false && ch3==false) {
      setCookie("layer","hosp",15);
    }
    else if (ch1==true && ch2==true && ch3==false) {
      setCookie("layer","hospFire",15);
    }
    else if (ch1==true && ch2==false && ch3==true) {
      setCookie("layer","hospPolice",15);
    }
    else if (ch1==false && ch2==true && ch3==true) {
      setCookie("layer","firePolice",15);
    }
    else if (ch1==false && ch2==true && ch3==false) {
      setCookie("layer","fire",15);
    }
    else if (ch1==false && ch2==false && ch3==true) {
      setCookie("layer","police",15);
    }
    else if ((ch1==false && ch2==false && ch3==false) || (document.getElementById("checkbox-h-2c").checked==true && ch2==true && ch3==true)) {
      setCookie("layer","hospFirePolice",15);
    }
    alert(getCookie("layer"));
    window.location = FACILITY_MAP;

1 Answers1

0

I'm not sure but from this other answer here on S.O. it seems that chrome blocks cookies unless they are set by the server. Here is what I found: 13801181

Also other post

And this discussion chromium

Credit goes to C5H8NNaO4 for finding them. Both of the latter links come from his answer

But I may be wrong.

Community
  • 1
  • 1
jkw4703
  • 352
  • 3
  • 17