If you want to update the cookies after some time interval using the time then call the below function.
Timer should run with the interval of less than 11 minutes.
updateCookieValue : function () {
var cookies = document.cookie.split(";");
if (cookies.length > 0) {
var nTime = new Date();
//add 11 mins to current time so that the recursive call to update cookie
(with interval 10 mins)
//gets executed before the cookie gets expired ( 11 * 1000 * 60)
// time added in millisecond
nTime.setTime(nTime.getTime()+660000);
for (var i = 0; i < cookies.length; i++){
var name = cookies[i].split("=")[0];
name = name.trim();
var value = cookies[i].split("=")[1];
if((name == " cookie_0") || (name == " cookie_1")){
document.cookie = name + "=" +escape( value ) +";expires="
+ nTime.toGMTString()+";path=/;domain=";
}
}
}
}
No comments:
Post a Comment