SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    May 2006
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to ask if cookie name already exists?

    Hello, how do I find out if a cookie name and cookie value already exists on a page. This doesn't seem to be working.

    Trying to say following if cookie name and value
    z,z does not exist then setCookie name and value z,z:

    function setCookie(name,value,days)
    {if(document.cookie != 'z,z'){
    var expires = "", date = new Date();
    if(days)expires = "; expires=" + new Date(date.setDate(date.getDate()+days)).toGMTString();
    document.cookie = name+"="+value+expires+"; path=/";
    setCookie('z', 'z', 365);}}

    But need some help. Please let me know how to check for if cookie name and value already exists. Thank you very much

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Use the following cookie handling functions
    http://www.quirksmode.org/js/cookies.html

    If readCookie('z') returns null then it doesn't exist
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

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