Results 1 to 6 of 6

Thread: How to read, write, delete and detect support for cookies?

  1. #1
    Join Date
    Aug 2006
    Posts
    162

    How to read, write, delete and detect support for cookies?

    I have started doing the JavaScript some time ago. I know what are the cookies.!! But how to read, write, delete and detect support for cookies in JavaScript.?? Please tell me some detailed information about the reading and writing of the cookies. Any other information related to the topic are warmly welcomed. Please help me as soon as possible.!!
    Technology is a way of organizing the universe so that man doesn't have to experience it.-- Max Frisch 1911 -1991

  2. #2
    Join Date
    Nov 2005
    Posts
    1,323

    Re: How to read, write, delete and detect support for cookies?

    If you want to read a cookie, it is very simple to do. The JavaScript interface to read the cookie is document.cookie. This interface contains a semicolon separated list of cookies. The following lines describes the style of the separated cookies :
    Code:
    "cookiename1=cookievalue1;...;cookienamen=cookievaluen".
    where cookiename1=cookievalue1; are the first cookie and
    cookienamen=cookievaluen are the last cookie. Only cookies for the current domain and path will be included in the string.

  3. #3
    Join Date
    Oct 2005
    Posts
    2,393

    Re: How to read, write, delete and detect support for cookies?

    You can also delete the cookies very easily. For deleting the cookie you should overwrite that cookie. The only way for deleting the cookie is by overwriting a cookie, and then setting the expiry time. By checking the following code you can understand more better :
    Code:
    document.cookie='cookiename=;'+
        'expires=Mon, 08-Feb-10 00:00:01 GMT;'+
        'path=path;'+
        'domain=domain";
    You should make sure that the path and domain must be the same as they were when the cookie was originally set. Otherwise the effect will not take place.

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: How to read, write, delete and detect support for cookies?

    The cookies are used in most cases, when the page reading the cookie appears before the page writing the cookie. There is a script by which you come to know that whether the cookie is available to read or not. The statement IF/ELSE are used for the cookie detection. The following code is simple form for detecting the cookies :
    Code:
    if (document.cookie){
    Code goes here if cookie exists}
    
    else{
    Code goes here if cookie does not exists}
    The above mentioned coding checks for any cookie set by your site.

  5. #5
    Join Date
    Mar 2008
    Posts
    349

    Re: How to read, write, delete and detect support for cookies?

    Writing the cookies in JavaScript is much complicated. The cookies that lives as long as the browser window are the easiest form of cookies, which are known as session-only cookies. You can write such cookies as the code that mentioned below :
    Code:
    document.cookie="cookiename=cookievalue";
    The cookies that live for the longer time are more advanced. Such cookies contain the string of the following pattern: "cookiename=cookievalue;path=path;expires=date;domain=domain;secure". In this the date should be in the form of the return from the toUTCString method of instances of JavaScript's Date object. You will have to change the default setting for the path, domain and secure parts.

  6. #6
    Join Date
    Jul 2006
    Posts
    289

    Re: How to read, write, delete and detect support for cookies?

    You can detect the cookie by the method described by 'opaper'. But the cookie detection can be more specific. The following code check for cookies with no value :
    Code:
    if (document.cookie && document.cookie != "")
    You can use the above code for testing the presence of a cookie. You can also come to know if its a "null" or blank string. Somethings that you should keep in mind while writing the code for the cookie detection :
    1. The code for cookie detection goes in the <head>'s <script> section of the page.
    2. In most cases the code should be placed outside any function.
    Signatures reduce available bandwidth

Similar Threads

  1. Replies: 5
    Last Post: 06-05-2012, 08:19 AM
  2. Replies: 10
    Last Post: 07-03-2012, 09:41 AM
  3. WinPatrol v.19.1.2010.1 is not able to detect cookies
    By ogusta89 in forum Windows Software
    Replies: 3
    Last Post: 27-12-2010, 01:21 AM
  4. How to write Cookies in Javascript
    By Janet J in forum Windows Software
    Replies: 3
    Last Post: 30-01-2009, 11:50 PM
  5. How to toggle between read-only and read-write in Word 2007
    By Mae Huckett in forum MS Office Support
    Replies: 1
    Last Post: 13-02-2008, 02:50 AM

Tags for this Thread

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
  •  
Page generated in 1,711,693,728.56039 seconds with 17 queries