Home >Web Front-end >JS Tutorial >JS reads cookie information (records user name)_javascript skills

JS reads cookie information (records user name)_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:57:151273browse

First, after the user submits a comment, let the client cookie record the relevant value. For example: the cookie assignment method under asp uses the following statement:

Copy code The code is as follows:

response.cookies("username")="name"
response.cookies("username").expires=Date 30


Assign values ​​to cookies through the above asp program. How to read this cookie in static page html and display it to the user? Because HTML is generated, we can no longer use the asp program to read this cookie. We need to read this cookie through js and assign it to the corresponding input value.

The code that uses js to read cookies and assign values ​​is as follows:
Copy the code The code is as follows:



In this way, the cookie information can be successfully read from the client in the static page and displayed.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn