Skip Navigation | Home | Code Samples | Articles | Links | About | Contact Me | Make a Payment

Cookie Object

Access the variables in the cookie object in two ways

To initialize the cookie object, just include the following 8 lines of code within a <script> block in the head of your document.

var dc = document.cookie;
var nv = dc.split('; ');
var cookie = new Object();
for(i = 0; i < nv.length; i++)
{
  eq = nv[i].indexOf('=');
  cookie[nv[i].substring(0, eq)] = unescape(nv[i].substring(eq + 1));
}

Alternatively, you can download an external JavaScript file and include it in your HTML document like this:.

<script language="JavaScript" type="text/javascript">
<!-- 
  var cookie = new Object();
// -->
</script>
<script language="JavaScript" type="text/javascript" src="{path to file}cookie.js"></script>