views:

23

answers:

1

I want to set cookies using javascript that should not expire for some time. I create the cookie using the code below. These cookies are available in firefox across browser session (browser restarts). However, all cookies seem to get lost in IE. I want to set the cookie using javascript only.

I alerted document.cookie on page load. In all firefox I see all the cookies set, however in IE I am getting an empty alert. After the page is loaded if I access document.cookie, I see all the cookies. However, the cookie set from Javascript is no more there.

To sum up, after a browser restart IE is destroying all cookies for the domain. Even the ones that have expiry set to future.

Here is the code.

function createCookie(name,value) {
    var date = new Date();
    date.setTime(date.getTime()+(30*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
    document.cookie = name+"="+value+expires+"; path=/";
}




function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}
A: 

I think this depends on privacy-settings. Did you change there something(are you browsing inPrivate?)

Dr.Molle