Reputation: 11071
I am trying to set a permanent cookie by JavaScript. I have something like:
document.cookie = name+'='+value+";expires="+(new Date(2019, 1, 1)).toUTCString();
It does not work. The cookie disappears when the browser is closed. Why is that? :(
Upvotes: 2
Views: 4268
Reputation: 13250
Try this
function setCookie(key, value) {
var expires = new Date();
expires.setTime(expires.getTime() + 31536000000); //1 year
document.cookie = key + '=' + value + ';expires=' + expires.toUTCString();
}
I have just set to 1 Year and you can change it to your convinience.
Upvotes: 2
Reputation: 5115
I believe you literally have to set a number of days. So like 10000 or however long you want it to last.
Upvotes: 1