You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

53 lines
1.1 KiB

/**
* createCookie - Creates a cookie with Name->Value pair, and will stay active for x hours
*
* @date 2019-11-08
* @author Rick Hays
* @param name
* @param value
* @param hours
*/
function createCookie(name, value, hours)
{
let expires = "";
if (hours)
{
let date = new Date();
date.setTime(date.getTime()+(hours*60*60*1000));
expires='' + date.toUTCString(); //.toGMTString();
}
document.cookie = name + '=' + value + '; expires=' + expires + "; path=/";
}
/**
* readCookie - reads the value of the name->value pair using the name, returns NULL if not found.
*
* @date 2019-11-08
* @author Rick Hays
* @param name
* @returns {string|null}
*/
function readCookie(name)
{
let nameEQ = name + "=";
let ca = document.cookie.split(';');
for(let i = 0; i < ca.length; i++)
{
let 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;
}
/**
* eraseCookie - erases cookie with the name->vaule pair.
*
* @date 2019-11-08
* @author Rick Hays
* @param name
*/
function eraseCookie(name)
{
createCookie(name,"",-1);
}