I really need help on where to put few simple cookie values wits end

Discussion in 'JavaScript' started by Jen-, Sep 14, 2008.

  1. #1
    Hello I have an alert for if the cookie is set, how do I add an alert to see how many days the cookie is set to expire? That way I know I'm setting the cookie correctly? Please let me know, thank you very much for your help


     
    Jen-, Sep 14, 2008 IP
  2. Logic Ali

    Logic Ali Well-Known Member

    Messages:
    170
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    108
    #2
    Don't you trust the function?
    You can alert the creation string as shown below. There is no way (or need) to read the expiry date of an existing cookie.

    <script type="text/javascript">
    function setCookie(name,value,days) 
    {
     var expires = "", date = new Date();
    
     if(days)
      expires = "; expires=" + new  Date(date.setDate(date.getDate()+days)).toGMTString();
    
     [COLOR="Red"]alert([/COLOR] document.cookie = name+"="+value+expires+"; path=/" [COLOR="red"])[/COLOR];
    }
    
    setCookie('ss', 'sss', 365);
    </script>
    
    Code (markup):
     
    Logic Ali, Sep 15, 2008 IP
  3. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #3
    MMJ, Sep 15, 2008 IP