I've recently created a small galiga like game recently using JavaScript and HTML5. I've run into a bit of trouble saving cookies, the cookie saves, but then resets itself when the page is refreshed, my code:
function saveScore() {
var date = new Date();
date.setMonth(date.getMonth()+5);
var expires = "; expires=" + date.toGMTString();
document.cookie = "score=" + lvl + expires + "; path=/";
}
function loadScore() {
var cookiearray = document.cookie.split(';');
for (var i = 0; i < cookiearray.length; i++) {
var name = cookiearray[i].split('=')[0];
var value = cookiearray[i].split('=')[1];
if (name == "score") {
alert("Prior score found. Loading score...");
lvl = value;
}
}
}
EDIT: It appears as though I made an error outside of the given code, and reset the level to zero, I fixed this, and everything works well, I apologize for any confusion caused.