js cookie11

The concept of cookie:

It is used to record the information generated by each HTTP session. When the next HTTP request is initiated, it will be sent to the server in one block. It will not be automatically recorded. It needs to be actively recorded.

Features of cookies:

1. Cookies can only store text (characters)

2. Cookie limit size, about 4k

3. The number of cookies is about 50

4. Cookies are not allowed to cross domains, and cross paths are not allowed

5. The cookie has a time limit, the default session level

The cookie itself is a local storage technology and does not require a server

Cookie will be sent to the server along with http, http must have a server

As long as the cookie is used, it will be sent by default

http will exist, and a server will be needed

Cookies must also be used in a server environment

Cookie operation:

Additions, deletions, modifications

Check: (View all)

consol.log(typeof document.cookie);

Increase: (except for reading, only one cookie can be operated at a time)

document.cookie = “user=admin”;

Set the expiration time:

var d = new Date();

var n = d.getDate() + 3;

var s = d.setDate (n);

document.cookie = “sex=1;expires=” + d;

Delete: (set the validity period to the past time)

var d = new Date();

var n = d.getDate() - 1;

var s = d.setDate (n);

document.cookie = “sex=1;expires=” + d;

Change: (Reset the same name with different values, or configuration information, just change)

var d = new Date();

var n = d.getDate() + 5;

var s = d.setDate (n);

document.cookie = “user=admin;expires=” + d;

document.cookie = “user=qewrqwr”;

Configuration information:

expires

path

Guess you like

Origin blog.csdn.net/qq_45555960/article/details/102773395