+ Reply to Thread
Results 1 to 4 of 4

Thread: Creating Cookies

  1. #1
    Co-Administrator John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John's Avatar
    Join Date
    Jul 2006
    Age
    21
    Posts
    5,885
    Blog Entries
    25

    Creating Cookies

    how can i create a cookie in java script? i basically want a function that does the equivilant of this in php

    Code:
    setcookie('clicked'"TRUE"time()+99999
    what i intend is to have a link, and when it is clicked, the javascript create a cookie

    HTML Code:
    <a href="http://www.google.com" onclick"CookieClick()">gooooogle</a>
    or something like that

    CookieClick() would then create the cookie

  2. #2
    Programmer Blaze is an unknown quantity at this point Blaze's Avatar
    Join Date
    Jun 2006
    Posts
    117
    You access them by the document.cookie

    Code:
    document.cookie =
      'ppkcookie1=testcookie; expires=Thu, 2 Aug 2001 20:47:11 UTC; path=/'
    1. First the name-value pair ('ppkcookie1=testcookie')
    2. then a semicolon and a space
    3. then the expiry date in the correct format ('expires=Thu, 2 Aug 2001 20:47:11 UTC')
    4. again a semicolon and a space
    5. then the path (path=/)


    From: http://www.quirksmode.org/js/cookies.html

  3. #3
    Co-Administrator John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John's Avatar
    Join Date
    Jul 2006
    Age
    21
    Posts
    5,885
    Blog Entries
    25
    that seems easy enough..also rather then specifying a specific date, would it be possable to create it so the cookies expire 24 hours after they are created (dynamically)

  4. #4
    Programming Expert Void is on a distinguished road Void's Avatar
    Join Date
    Jun 2006
    Posts
    410
    Yes, here is some code:

    Code:
    var expireDate = new Date()
    expireDate.setHours(expireDate.getHours()-10)
    Add it here:

    Code:
    document.cookie =
      'ppkcookie1=testcookie; path=/; expires=' + expireDate.toGMTString();
    However, this is untested. I just took it from some other code on the web.
    Void

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Creating a Clock
    By AfTriX in forum VB Tutorials
    Replies: 1
    Last Post: 05-08-2009, 10:33 AM
  2. Creating an analog clock with ActionScript
    By AfTriX in forum Tutorials
    Replies: 2
    Last Post: 01-07-2007, 02:19 AM
  3. Cookies
    By dirkfirst in forum HTML Programming
    Replies: 10
    Last Post: 01-06-2007, 04:11 AM
  4. Creating a backup script
    By NeedHelp in forum General Programming
    Replies: 3
    Last Post: 09-07-2006, 05:14 AM
  5. Creating Tables
    By leon in forum Database & Database Programming
    Replies: 2
    Last Post: 06-12-2006, 09:02 AM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

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