1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
// From http://www.quirksmode.org/js/cookies.html
// Create a new cookie for the sever, valid for the given number of days.
// If days is null, then the cookie will expire when the browser is closed
// If days is -1, the cookie is erased
//
// Path is the URL in the domain for which the cookie should be sent. By
// default this is '/'.
function createCookie(name,value,days,path)
{
if (days)
{
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
if (path)
var fullpath=path;
else
var fullpath="/";
document.cookie = name+"="+value+expires+"; path="+fullpath;
}
// Read the value for a given cookie
// null is returned if there is no such cookie
function readCookie(name)
{
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++)
{
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
// Erase a given cookie
function eraseCookie(name)
{
createCookie(name,"",-1);
}
|