Results 1 to 4 of 4

Thread: How to write Cookies in Javascript

  1. #1
    Join Date
    Jan 2009
    Posts
    150

    How to write Cookies in Javascript

    Hello Friends,

    In my web browser I wanted to set cookies which will help me in showing the Visited sites in the site address name,day,date and time, please help me giving some idea about the same.

    I know this is possible but I stuck where should I starts from.


    Any help would be Appreciated

  2. #2
    Join Date
    Feb 2008
    Posts
    121

    Re: How to write Cookies in Javascript

    Cookies in JavaScript are accessed using the cookie property of the document object. In simple terms, we create a cookie like this:

    Code:
    document.cookie = "name=value; expires=date; path=path;
                       domain=domain; secure";
    ..and retrieve all our previously set cookies like this:

    Code:
    var x = document.cookie;
    Let's look more closely at how to set and retrieve cookies.To set a cookie, we set the document.cookie property to a string containing the properties of the cookie that we want to create:

    document.cookie = "name=value; expires=date; path=path;
    domain=domain; secure";

  3. #3
    Join Date
    Feb 2008
    Posts
    180

    Re: How to write Cookies in Javascript

    It would be more difficult to explain all about the Cookie but i can tell you where we can store the Cookie,Physically, cookies are stored in a location known only to the browser, although for the main browser platforms, these locations are well-known. Logically, a cookie belongs to a domain and a path. When the JavaScript set cookies process is invoked, the script either presents the browser with a domain, or a blank value. If no domain is given it is assumed to be the domain of the page

  4. #4
    Join Date
    Feb 2008
    Posts
    129

    Re: How to write Cookies in Javascript

    First, we create a function that stores the name of the visitor in a cookie variable:

    Code:
    function setCookie(c_name,value,expiredays)
    {
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+
    ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
    }
    The parameters of the function above hold the name of the cookie, the value of the cookie, and the number of days until the cookie expires.

Similar Threads

  1. Replies: 10
    Last Post: 07-03-2012, 09:41 AM
  2. How to read, write, delete and detect support for cookies?
    By Flaco in forum Software Development
    Replies: 5
    Last Post: 03-02-2010, 03:33 AM
  3. Inplant cookies in Javascript
    By Xmen in forum Software Development
    Replies: 2
    Last Post: 28-11-2009, 12:47 PM
  4. How to write javascript isobject
    By Zombi in forum Software Development
    Replies: 3
    Last Post: 28-07-2009, 11:54 AM
  5. Replies: 2
    Last Post: 20-06-2009, 12:16 PM

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,714,045,642.69597 seconds with 17 queries