What is cookie?
This article mainly introduces "what is cookie". In daily operation, I believe many people have doubts about what is cookie. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts about "what is cookie?" Next, please follow the editor to study!
1. What is cookie?
Cookie is the browser cache
What is caching? Buffer for data exchange > temporary storage.
Cookie features. Cookie takes effect under the same domain name. Cookie storage is limited. 4: 10k, can not store 50, there is expiration time.
> caching
2.cookie usage
[xss_clean] =''
Format requirements for cookie. Name = value
Session cookie
Review the Date object
What do the parameters in setDate () do after the date time is exceeded?
SetDate (getDate () + 8000)
Expires=
'user=yanghuaizhi;expires='+d
Encapsulated cookie
Function setCookie (name,value,expirs) {
Var d=new Date ()
D.setDate (d.getDate () + expirs)
[xss_clean] = name+'='+value+';expires='+expirs
}
Get cookie
Function getCookie (name) {
Var arr=doucment.cookie.split (';')
For (var I = 0; I < arr.length; I + +) {
Var arr2= arr [I] .split ('=')
If (arr2 [0] = = name) {
Return arr2 [1]
}
}
Return''
}
Debugging of cookie:
3. Delete cookie
Function removeCookie (name) {
SetCookie (name,1,-1); / / 1 is an arbitrary value, which can be any value;-1 is the expiration time
}
Encapsulation of cookie
Var cookie= {
SetCookie:function (name,value,date) {
Var d=new Date ()
D.setTime (d.getTime () + date)
[xss_clean] = name+'='+value+';expires='+d
}
GetCookie:function (name) {
Var arr= [XSS _ clean] .split (';')
For (var I = 0; I < arr.length; I + +) {
Var arr2= arr [I] .split ('=')
If (arr2 [0] = = name) {
Return arr2 [1]
}
}
Return''
}
RemoveCookie:function (name) {
Cookie.setCookie (name,'',-1)
}
}
At this point, the study of "what is cookie" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!