﻿<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ladysign Dev Blog &#187; cookies</title>
	<atom:link href="http://www.ladysign-apps.com/blog/tag/cookies/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ladysign-apps.com/blog</link>
	<description>Girls can code.</description>
	<lastBuildDate>Mon, 01 Feb 2010 09:44:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Cookies in Javascript</title>
		<link>http://www.ladysign-apps.com/blog/code/javascript/cookies-in-javascript/</link>
		<comments>http://www.ladysign-apps.com/blog/code/javascript/cookies-in-javascript/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 15:10:00 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[cookies]]></category>

		<guid isPermaLink="false">http://ladysign-apps.com/blog/?p=791</guid>
		<description><![CDATA[<p><strong>Difficulty:</strong> 2 out of 5 stars<br />
A cookie (also tracking cookie, browser cookie, and HTTP cookie) is a small string of text stored on a user&#8217;s compu[......]</p>]]></description>
			<content:encoded><![CDATA[<p><strong>Difficulty:</strong> 2 out of 5 stars<br />
A cookie (also tracking cookie, browser cookie, and HTTP cookie) is a small string of text stored on a user&#8217;s computer by a web browser. A cookie consists of one or more name-value pairs containing bits of information.<br />
Beside the name/value pair, a cookie may also contain an expiration date, a path, a domain name, and whether the cookie is intended only for encrypted connections. These pieces of data follow the name=newvalue pair and are separated by semicolons. For example, a cookie can be created by the server by sending a line </p>
<pre class="brush: jscript;">Set-Cookie: name=newvalue; expires=date; path=/; domain=.example.org.</pre>
<p>With Javascript you can also set cookies. It&#8217;s not hard at all. I think it&#8217;s useful for folding/unfolding or hiding/displaying CSS content. This part of Javascript I wrote for setting, getting and deleting a cookie:</p>
<pre class="brush: jscript;">/*
* Set the cookie
* @param name - the name of the cookie variable
* @param value - the value of the variable which will be saved in the cookie.
* @expires - the
*/
function setCookie(name, value, expires) {
	var today = new Date();  //set new date object
	var defaultDays = 30;
	today.setTime(today.getTime());
	if (expires) {
		expires = expires * 1000 * 60 * 60 * 24;
	}else{
		expires = defaultDays * 1000 * 60 * 60 * 24;
	}

	document.cookie = name + &quot;=&quot; + escape(value) +
        &quot;; path=/&quot; + ((expires == null) ? &quot;&quot; : &quot;; expires=&quot; +
        expires.toGMTString());
}

/*
 * Get Cookie
 * @param: name of the cookie variable you would like to retrieve
 */
function getCookie(name) {
	var cookieValue = null;
	var startPos = document.cookie.indexOf(name+&quot;=&quot;);
	var lengthVal = startPos + name.length + 1;

	if((startPos)&amp;&amp;(startPos&gt;0)&amp;&amp;
        (name == document.cookie.substring(0, name.length))){
		var endPos = document.cookie.indexOf( &quot;;&quot;, lengthVal);

		if (endPos == -1){
			endPos = document.cookie.length;
		}
		cookieValue = unescape(
                   document.cookie.substring(lengthVal, endPos)
                );
	}

	return cookieValue;
}

/*
 * Delete Cookie
 * @param delete the cookie variable by passing the name
 */
function delCookie(name) {
    document.cookie = name +
    &quot;=; expires=Thu, 01-Jan-70 00:00:01 GMT&quot; + &quot;; path=/&quot;;
} </pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ladysign-apps.com/blog/code/javascript/cookies-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
