When developing a Web page based on micro-trust, it was found that some models could not store information in Localstorage, or that once the page was closed, the stored information was invalidated.
Use cookies instead of Localstorage to store some simple data. Search the Internet, found that W3school has a good solution.
To set Cookies:
function Setcookie (c_name,value,expiredays)
{
var exdate=new Date ()
exdate.setdate (exdate.getdate () + expiredays)
document.cookie=c_name+ "=" +escape (value) + (
(expiredays==null)? ' ': '; expires= ' +exdate.togmtstring ()
}
///Retrieve cookie
function GetCookie (c_name)
{
if ( document.cookie.length>0)
{
c_start=document.cookie.indexof (c_name + "=")
if (c_start!=-1)
{
C_start=c_start + c_name.length+1
c_end=document.cookie.indexof (";", C_start)
if (c_end==-1 ) C_end=document.cookie.length return
unescape (document.cookie.substring (c_start,c_end))
}
} Return
""
}
Example:
Set cookies, valid for 365 days
Setcookie (' username ', ' 123 ', 365);
Retrieve, if the cookie fails, will return empty
GetCookie (' username ');
Tested, fully compliant, no problem. There is a need for small partners can refer to, thank you support!