Reputation: 95
I have a problem with my cookies. I set and get a cookie in my local javascript, and it works fine with Firefox. But Chrome ignore this cookie. I'll use my local javascript long, and I want to know if we can allow local cookies. I simply set the cookie like that:
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + "; " + expires + "; path=/";
}
function getCookie(cname) {
var name = cname + "=";
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);
if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
}
return "";}
And then:
setCookie("key",jsonRet.key,1000);
setCookie("login",jsonRet.login,1000);
setCookie("id",jsonRet.id,1000);
Thanks.
Upvotes: 0
Views: 666
Reputation: 395
Are you using file://? Chrome does not deal with that though Firefox does.
Upvotes: 2