SoFunction
Updated on 2025-02-28

JavaScript operation cookie method function collection page 1/2


// utility function to retrieve an expiration data in proper format;
function getExpDate(days, hours, minutes)
{
var expDate = new Date();
if(typeof(days) == "number" && typeof(hours) == "number" && typeof(hours) == "number")
{
(() + parseInt(days));
(() + parseInt(hours));
(() + parseInt(minutes));
return ();
}
}
//utility function called by getCookie()
function getCookieVal(offset)
{
var endstr = (";", offset);
if(endstr == -1)
{
endstr = ;
}
return unescape((offset, endstr));
}
// primary function to retrieve cookie by name
function getCookie(name)
{
var arg = name + "=";
var alen = ;
var clen = ;
var i = 0;
while(i < clen)
{
var j = i + alen;
if ((i, j) == arg)
{
return getCookieVal(j);
}
i = (" ", i) + 1;
if(i == 0) break;
}
return;
}
// store cookie value with optional details as needed
function setCookie(name, value, expires, path, domain, secure)
{
= name + "=" + escape(value) +
((expires) ? "; expires=" + expires : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}
// remove the cookie by setting ancient expiration date
function deleteCookie(name,path,domain)
{
if(getCookie(name))
{
= name + "=" +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}