Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 03-02-2010
Member
 
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
Reply With Quote
  #2  
Old 03-02-2010
Member
 
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.
Reply With Quote
  #3  
Old 03-02-2010
Member
 
Join Date: Oct 2005
Posts: 2,389
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.
Reply With Quote
  #4  
Old 03-02-2010
Member
 
Join Date: May 2008
Posts: 2,383
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.
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #5  
Old 03-02-2010
Member
 
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.
Reply With Quote
  #6  
Old 03-02-2010
Member
 
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
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to read, write, delete and detect support for cookies?"
Thread Thread Starter Forum Replies Last Post
Internet Explorer 9 wont delete cookies when set to delete all history on exit Ritesh Singh Technology & Internet 5 06-05-2012 08:19 AM
Internet explorer 9 displays Cookies error message? IE9 works better when it is cookies enabled, please enable cookies? Bellare Technology & Internet 10 07-03-2012 09:41 AM
WinPatrol v.19.1.2010.1 is not able to detect cookies ogusta89 Windows Software 3 27-12-2010 01:21 AM
How to write Cookies in Javascript Janet J Windows Software 3 30-01-2009 11:50 PM
How to toggle between read-only and read-write in Word 2007 Mae Huckett MS Office Support 1 13-02-2008 02:50 AM


All times are GMT +5.5. The time now is 04:25 PM.