Notice This is a beta feature offered by Google. Also this is automatic translation, which means the results are often inacurate and/or hilarious. Enjoy.

Cookie.js

Cookie.js is a small JavaScript library to manipulate cookies. No external libraries are needed.

Please note that it is still in alpha development and might (probably) still contain some bugs. If you find one please report it to me, I'll be happy to fix them.

Example

Here a very simple example of how you can use this script:

HTML
<input id="ctest" type="button" value="Click me" onclick="testCookie();" />
JavaScript
function testCookie() {
  if (Cookie.test()) {
    if (Cookie.get('testCookie')) {
      alert('Cookie was set, now unsetting.');
      Cookie.unset('testCookie');
      $('ctest').value = "Click me";
    }
    else {
      alert('Cookie was not set, now setting test cookie.');
      Cookie.set('testCookie','true');
      $('ctest').value = "Click me again !";
    }
  }
}

Demo

Methods

Cookie.get Get a cookie's value
Cookie.set Set a cookie
Cookie.unset Unset a cookie
Cookie.test Return true if cookie functionnalities are available
Cookie.dump If Firebug JavaScript console is present, it will dump cookie string to console.
Cookie.hoursToExpireDate Return GTM date string of "now" + time to live

Downloads

SVN users who wants to checkout the trunk use this:

<p><div class="code_highlight"><pre>svn checkout http://cookie-js.googlecode.com/svn/trunk/ cookie-js </pre></div> </p>

Don't hesitate to send me comments, fixes or ideas, I'm open to suggestions!

Copyrighted stuff .. u know.