The code copy is as follows:
// Verified
// JavaScript Document
//Instructions for use:
//Set cache: setCookie("name",value);
//Get cache: var name=getCookie("name");
//Delete cache: delCookie("name");
///Set cookies
function setCookie(NameOfCookie, value, expiredays)
{
//@parameters: Three variables are used to set new cookies:
//The name of the cookie, the stored cookie value,
// and the time when the cookie expires.
// These lines are the days that convert the number of days to legal dates
var ExpireDate = new Date ();
ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
// The following line is used to store cookies, you just need to simply assign a value to "document.cookie".
// Note that the date is converted to GMT time through the toGMTstring() function.
document.cookie = NameOfCookie + "=" + escape(value) + ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}
///Get the cookie value
function getCookie(NameOfCookie)
{
// First, let’s check whether the cookie exists.
// If not present, the length of document.cookie is 0
if (document.cookie.length > 0)
{
// Next, let's check whether the cookie's name exists in document.cookie
// Because more than one cookie value is stored, even if the length of the document.cookie is not 0, it cannot guarantee that the cookie of the name we want exists.
//So we need this step to see if there are any cookies we want
//If the begin variable is worth -1, it means that it does not exist
begin = document.cookie.indexOf(NameOfCookie+"=");
if (begin != -1)
{
// Indicates that our cookies exist.
begin += NameOfCookie.length+1;//The initial position of the cookie value
end = document.cookie.indexOf(";", begin);//end position
if (end == -1) end = document.cookie.length;//No; then end is the end position of the string
return unescape(document.cookie.substring(begin, end));
}
}
return null;
// The cookie does not exist and returns null
}
///Delete cookies
function delCookie (NameOfCookie)
{
// This function checks whether the cookie is set. If it is set, the expiration time will be adjusted to the past time;
//Leave the rest to the operating system to clean up the cookies at the appropriate time
if (getCookie(NameOfCookie))
{
document.cookie = NameOfCookie + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}