JavaScript is a script that runs on the client, so it is generally not possible to set the session because the session is running on the server side.
The cookie is run on the client, so you can use JS to set the cookie.
Suppose there is a case, in a use case process, a page jumps to page B, if the a page with the variable temp Save the value of a variable, in the B page, also need to use JS to reference the variable value of temp, for JS in the global variable or static variable life cycle is limited, When a page jump occurs or the page closes, the values of these variables are re-loaded, that is, the saved effect is not achieved. The best solution to this problem is to use a cookie to hold the value of the variable, so how do you set and read the cookie?
First, we need to understand a little bit about the structure of the cookie, simply: The cookie is stored in the form of a key-value pair, the Key=value format. Each cookie is generally ";" Separated.
How to use
JS set cookies, read cookies, delete cookies