1

Cookie not save in IE but working fine in other browsers. I am using document.cookie .

Example :

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

function getCookie(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 == name) {
            return unescape(y);
        }
    }
}
Tushar
  • 85,780
  • 21
  • 159
  • 179
userknowmore
  • 137
  • 2
  • 14

1 Answers1

1

I am presuming, you are running your script from local machine and none the web page is opened its like about:blank opened. Recently, I faced a similar issue. My script couldn't store a cookie in IE in this case, although it worked well on all other major browsers. After some googling it turned out that IE ignores cookies from about:blank. After I uploaded the page to remote server code magically started to work.

I have opened Google and run your code it is working fine in IE9.

And I am hoping you have made required setting in browser(IE) settings. Like below

  1. Open Internet Explorer 9
  2. Click on the Tools icon on the very right at the top and then on Internet Options.
  3. At the top switch to the tab Privacy and click on the Advanced button.
  4. Allow First-Party Cookies and Third-Party Cookies and enable Session Cookies (As per your requirement).
SK.
  • 4,174
  • 4
  • 30
  • 48