Preface
Cookie settings
Parameter description:
name cookie name, key value
value optional, cookie value
expire optional, expiration time, timestamp format
path optional, the server-side valid path, / means that the entire domain name is valid, and the default is the path of the page when the cookie is currently set.
domain optional, the cookie is a valid domain name
Secure is optional. Specifies whether cookies are transmitted over a secure HTTPS connection.
Encapsulation of code
(function(){ var cookieObj={ 'add':function(name, value, hours){ //Modify or add cookies var expire = ""; if(hours != null){ expire = new Date((new Date()).getTime() + hours * 3600000); expire = "; expires=" + expire.toGMTString(); } document.cookie = name + "=" + escape(value) + expire + ";path=/"; //If you specify a domain name, you can use the following //document.cookie = name + "=" + escape(value) + expire + ";path=/;domain=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 all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.