iLTC Home
Bookmark iLTC!

Categories

Perl
  • Perl Tutorials Beginners

  • Javascript
  • Javascript Tutorials
  • Javascript Tutorials Beginners

  • HTML
  • HTML Tutorials

  • Command Line
  • Command Line Tutorials

  • How Tos
  • Other Tips and Tricks



  • $koko =~ s/\./:)/g;
    2210943

    iLoveTheCode.com

    Setting a Cookie using Javascript

    To set cookies in Javascript use document.cookie

    document.cookie="iltccook=got it;domain=ilovethecode.com;expires=Mon, 18-Feb-2036 05:43:38 GMT;path=/";

    -You named your cookie iltccook because you like the way it sounds.
    -You give it a value of got it because you think it's clever.
    -When a user accesses your page that contains this script, they will get a cookie that lasts until 2036.


    NOTES:
    -The domain value must be your domain or subdomain (the domain where the script is).
    -The time must be in this format Mon, 18-Feb-2036 05:43:38 GMT
    -20 cookie per domain limit


    You can give the cookie more than one value like so:

    var huhu="got it,got more,and still more";

    document.cookie="iltccook=" + huhu + ";domain=ilovethecode.com;expires=Mon, 18-Feb-2036 05:43:38 GMT;path=/";


    NOTES:
    -We use plus symbols to insert our variable huhu into the cookie.
    -Cookies with the same name overwrite the previous cookie.


    To print the cookie back to the browser:

    var ko=document.cookie;

    document.write(ko);

    or

    document.write(document.cookie);


    To see your all your cookies:
    Mac Firefox - Preferences > Privacy > View Cookies > Then search for your domain
    Mac Safari - Preferences > Advanced > Show Cookies
    Windows Firefox - Tools > Options... > Privacy > Cookies > View Cookies
    Windows IE - Tools > Internet Options... > General (Tab) > Settings... > View Files...


    Free Copy and Paste Javascript Code (change domain to your domain; change name and value if you like):

    <script type="text/javascript">
    <!--

    //set cookie number one - iltccook

    document.cookie="iltccook=got it;domain=ilovethecode.com;expires=Mon, 18-Feb-2036 05:43:38 GMT;path=/";


    //set cookie number two - iltccook2

    var huhu="got it,got more,and still more";

    document.cookie="iltccook2=" + huhu + ";domain=ilovethecode.com;expires=Mon, 18-Feb-2036 05:43:38 GMT;path=/";


    //print cookies set by this domain

    document.write(document.cookie);

    -->
    </script>



    Resources:
    Formatting Time in Javascript
    Reading Cookies using Javascript
    Search Google for "Javascript Set Cookie"
    Microsoft - Specs for Date and Time Formatting
    Web Monkey Cookie Tutorial
    Spltting an Array in Javascript




    Previous Article: Splitting an Array using Javascript
    Next Article: Reading Cookies using Javascript






    Search iLTC w/ Google




    Recent Articles

  • HTML Font Code
  • Javascript and CSS - Easy Pop Up Help Balloons
  • Use OnMouseOver in Javascript
  • Use onMouseOut in Javascript
  • Use innerHTML to Change Text on a Page
  • Renaming a File with Perl's RENAME Function
  • PRINT to Browser with document.write Command in Javascript
  • Passing an Argument or Variable to a Javascript
  • Opening an Alert Box in Javascript
  • Opening a REMOTE WINDOW in Javascript
  • OPEN and WRITE a Data File in Perl
  • OPEN and READ a Data File in Perl
  • Mimic Typing from a Textfield in a Textarea with Javascript
  • Javascript Reset Form








  • Perl Programming - Javascript Programming - HTML Code - Mac Unix Command Line - Maybe Some PHP - Free Scripts - ILoveTheCode
    All Content © 2006-2009 iLoveTheCode.com


    Contact Chris | About this Site


    2210154
    Counter by iLoveTheCode.com


    Last Modified: Saturday, 10-Jan-2009 05:40:25 EST



    Hosted as well :)
    Home-brewed logo - 1997