Hi,
I trying to get a cookie to last two minutes (example below) and when the two minutes expires to stop showing a div and never show it again. Below the “div” would be where it says “do stuff here”.
The code below doesn’t automatically stop the div from showing and then on refresh it creates a new cookie!
This might not be the right kind of code? How can I accomplish this?
function createCookie(name,value,days) {
var expires = "";
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days*2*60*1000));
expires = "; expires=" + date.toUTCString();
}
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;
}
function eraseCookie(name) {
createCookie(name,"",-1);
}
createCookie('ppkcookie','testcookie',1);
var x = readCookie('ppkcookie')
if (x) {
//do stuff here
}