Objective
Cookie settings
Parameter description:
Name Cookie, key value
Value optional, cookie values
Expire optional, expiration time, timestamp format
Path optional, server-side valid path,/means the entire domain name is valid, and defaults to the path of the page when the cookie is currently set
Domain optional, the cookie is valid
Secure optional. Specify whether to transmit cookies through a secure HTTPS connection.
Encapsulation of code
(function () {
var cookieobj={
' Add ': function (name, value, hours) {//modify or add a cookie
var expire = "";
if (hours!= null) {
expire = new Date (new Date ()). GetTime () + hours * 3600000);
expire = "; Expires= "+ expire.togmtstring ();
}
Document.cookie = name + "=" + Escape (value) + expire + ";p ath=/";
If the specified domain name can be used as follows
//document.cookie = name + "=" + Escape (value) + expire + ";p ath=/;d Omain=findme.wang";
},
' Get ': function (c_name) {//Read Cookie
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
"";
}
;
window.cookieobj=cookieobj;
} ());
Call Test
Cookieobj.add (' MyWeb ', ' Http://www.findme.wang ');
Console.log (' MyWeb: ' +cookieobj.get (' website '));
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.