Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Nov 2004
    Posts
    64
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with cookies

    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?
    Code:
    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');
    }
    

  • #2
    Regular Coder
    Join Date
    Jan 2004
    Location
    Port Huron, MI, U.S.A.
    Posts
    280
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can't do if (#var==NaN), rather you must do if (isNaN(#var))
    Oh, was I supposed to put something here? ........


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •