Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of js cookie Operation

Shulou Source: shulou.com Published: 2022-06-02 08:39:30 10月04日 Update

This article mainly introduces the example analysis of js cookie operation, which has a certain reference value, and interested friends can refer to it. I hope you will gain a lot after reading this article.

CookieObj=function () {}

CookieObj.prototype.clearCookie = function () {

Var now = new Date ()

Var yesterday = new Date (now.getTime ()-1000 * 60 * 60 * 24)

This.setCookie ('co'+this.obj,' cookieValue', yesterday)

This.setCookie ('cs'+this.obj,' cookieValue', yesterday)

}

/ / [Cookie] Sets value in a cookie

CookieObj.prototype.setCookie = function (cookieName, cookieValue, expires, path, domain, secure) {

[xss_clean] =

Escape (cookieName) +'='+ escape (cookieValue)

+ (expires?'; expires=' + expires.toGMTString ():'')

+ (path?'; path=' + path:'')

+ (domain?'; domain=' + domain:'')

+ (secure?'; secure':'')

}

/ / [Cookie] Gets a value from a cookie

CookieObj.prototype.getCookie = function (cookieName) {

Var cookieValue =''

Var posName = [xss_clean] .indexOf (escape (cookieName) +'=')

If (posName! =-1) {

Var posValue = posName + (escape (cookieName) +'=') .length

Var endPos = [xss_clean] .indexOf (';', posValue)

If (endPos! =-1) cookieValue = unescape ([xss_clean] .substring (posValue, endPos))

Else cookieValue = unescape ([xss_clean] .substring (posValue))

}

Return (cookieValue)

}

/ / [Cookie] Returns ids of open nodes as a string

DTree.prototype.updateCookie = function () {

Var str =''

/ / find the key value key to be modified

This.setCookie ('co' + key, str)

}

Thank you for reading this article carefully. I hope the article "sample Analysis of js cookie Operation" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Articles examples analysis value interest at the same time more friends knowledge editing industry information information channels channels references learning help support Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Microsoft macOS MariaDB OPPO Reno