Hi,
I’m trying to create a div popup (yes, I know) that repeatedly appears every 7 minutes. It needs to work regardless of whether a user refreshes or navigates to different pages within the site, so I’m attemping to use a cookie to stop the timer from restarting every time the user changes page or refreshes.
My thinking’s like this:
1. set cookie = current time2. every 5 seconds check to see if current time is >= to cookie + 7 minutes3. When it is popup div and clear cookie4. On close of div popup repeat previous steps
With my VERY limited knowladge of javascript this is what I’ve got as the JavaScript for the cookie/popup trigger: It doesn’t even appear to be setting the cookie currently. Can anyone help and tell me what am I doing wrong? I’d really appreciate it. Thanks.
[CODE]
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = “; expires=”+date.toGMTString();
}
else var expires = “”;
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);
}
function popup_cookie() {
var x = getTime;
createCookie(‘popup_cookie_01’,x,0);
}
function open_float() {
setVisible(‘floating_layer’);
return false;
}
function popup() {
var y = getTime;
var x = readCookie(‘popup_cookie_01’);
if y >= (x + 420000) {
open_float();
eraseCookie(‘popup_cookie_01’);
}
}
function check_popup() {
setInterval(“popup()”,5000)
}
function exit_float() {
popup_cookie();
setVisible(‘floating_layer’);
return false;
}
addLoadEvent(popup_cookie)
addLoadEvent(check_popup)