...

View Full Version : Help with cookies



6arredja
03-07-2005, 05:52 PM
when i run this on a computer i get the alert that displays the value of visits ,but when it goes to the check {if(visits==NaN)} it doesnt catch it. What am i doing wrong?


function getCookie(NameOfCookie)
{ if (document.cookie.length > 0)
{ begin = document.cookie.indexOf(NameOfCookie+"=");
if (begin != -1)
{ begin += NameOfCookie.length+1;
end = document.cookie.indexOf(";", begin);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(begin, end)); }
}
return null;
}
function setCookie(NameOfCookie, value, expiredays)
{ var ExpireDate = new Date ();
ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
document.cookie = NameOfCookie + "=" + escape(value) +
((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}
function delCookie (NameOfCookie)
{ if (getCookie(NameOfCookie)) {
document.cookie = NameOfCookie + "=" +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}

visits = parseInt(getCookie('visits'));
alert(visits);
if(visits=='NaN'|visits == 'null')
{
alert('This computer has never seen this page');
}

Bobo
03-07-2005, 09:15 PM
You can't do if (#var==NaN), rather you must do if (isNaN(#var))



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum