Cookie Handler
10
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 );
}
{
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 );
}
Comments
Voting
Votes Up
ColdKeyboard
dannyboy
i_kenneth
lolfejs
mattrmiller
Pio
RatNuShock
SecondV
shachi
sundaramkumar
svachon






-----------------------
http://jiart.org/
My digital playground with it's own sandbox.
Well anyway, I love programming
=================
Matthew R. Miller
http://bluecreststudios.com
http://www.codeandcoffee.com