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 to the CF scene
    Join Date
    Jun 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Solution to Cookies

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <script type="text/javascript" src="cookies.js"></script>
    </head>

    <body>
    <script>
    if(getCookie('username')){
    alert("welcome back, " + getCookie('username'))}
    else{
    var myname = prompt("What's your name?", "");
    setCookie('username', myname, 365)
    }
    </script>
    </body>
    </html>








    Cookies.ks
    function setCookie(name, value, expiredates)
    {
    var exp = new Date ();
    exp.setTime(getTIme()+ expiredates);
    document.cookie = name+"="+value;expires+"="+exp.toGMTString();
    }

    function getCookie(name)
    {
    if (document.cookie.length>0)
    {
    c_start=document.cookie.indexOf(name + "=")
    if (c_start!=-1)
    {
    c_start=c_start + name.length+1
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end))
    }
    }
    return ""
    }
    Last edited by heldl; 06-16-2007 at 10:47 PM.

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    And what is your question or reason for posting this? Helps if you add text and not just code.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]


  •  

    Posting Permissions

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