Cookie Handler





10
Date Submitted Fri. Feb. 10th, 2006 7:52 AM
Revision 1 of 1
Helper lilleman
Tags Cookie | Handler | JavaScript
Comments 2 comments
Cookie Handle
function Cookie(name)
{
  this.name = name;
}

Cookie.prototype.set = function(value, expires, path, domain, secure)
{
  if( expires )
  {
    var date = new Date();
                date.setTime(date.getTime()+(expires*86400000));
                var expires = "; expires=" + date.toGMTString();
  }
 
  document.cookie = this.name + '=' + escape(value)
    + ( expires ? '; expires=' + expires : '' )
    + ( '; path=' + ( path ? path : '/' ) )
    + ( domain ? '; domain=' + domain : '' )
    + ( secure ? '; secure' : '' );
}

Cookie.prototype.get = function()
{
  if( !this.exists() ) return;
 
  var nameEQ = this.name + '=';
  var cookies = document.cookie.split(';');
 
  for( current in cookies )
  {
    var c = cookies[current].replace(/^\s+/, '');
    if( c.indexOf(nameEQ) == 0 ) return c.substr(nameEQ.length);
  }
}

Cookie.prototype.drop = function() { this.set('', 0); }

Cookie.prototype.exists = function()
{
  return ( document.cookie.indexOf(this.name + '=') != -1 );
}

Erik Riklund

phofer.com

Comments

Comments Looking good
Thu. Jul. 27th, 2006 6:54 AM    Helper rastersize
Comments Cool
Mon. Feb. 13th, 2006 1:44 AM    Coder mattrmiller

Voting