MENU service case
 Website construction website design Beijing website construction high-end website production company Shangpin China
We create by embracing change
360 ° brand value__
simplified Chinese character
Simplified Chinese English

Shangpin China Joins Hands with Beisheng Internet to Create a New Chapter in Website Construction

Type: Shangpin Dynamic Learn more

Website production tutorial javascript client data storage mechanism cookie

Source: Shangpin China | Type: website encyclopedia | Time: December 13, 2015
Cookies, translated into Chinese as cookies, are just a small piece of information in the browser cache, Website production Users can be identified, such as whether the monthly user has visited for the first time, what content has been browsed, etc. It can also be used to verify whether the user logs in to the website, so that the user can log in to the website only once, and does not need to log in again the next time. In short, cookies are very useful. JavaScript can easily set, obtain and delete cookies. Check the application case of code 1-9.

 Cookie code
 Cookie code

Save the above code as "cookie. htm", open it with a browser, and the result is as shown in Figure 1.20.

 Cookie operation

Code analysis: In the JavaScript footer of the above example, there are structures and key words that have never been seen before.

 setcookie

The function that starts with the keyword "function" is called a function, followed by the function name "setCookie", and the parameter name, value, and days are enclosed in parentheses after the function name. There are three such functions in this code. These three functions are not run immediately after they are defined. For example, the "setCookie" function is run only when it is called in line 31 of the code. There is no "function" keyword when calling the function. At the same time, the parameters after the function name are replaced with the values expected to be passed to the function. This is because the function is like a machine that can be used only after it is built. Lines 7-26 are used to build the function, and lines 31, 34, 37, and 40 are used to use the function. The setCookie function in line 31 sets a cookie named "dan" with a value of "3333 'and a validity period of" 60 "days. In line 34, the number of getCookies gets the cookie value named" dan ". If there is a value, the set value will be displayed. If there is no cookie named" dan "," null "will be displayed. In line 37, the delCookie function deletes the cookie named" dan ". In line 40, the getCookie function is called again to display the value of "dan". At this time, "null" is displayed because the cookie named "dan" has been deleted.
Source Statement: This article is original or edited by Shangpin China's editors. If it needs to be reproduced, please indicate that it is from Shangpin China. The above contents (including pictures and words) are from the Internet. If there is any infringement, please contact us in time (010-60259772).
TAG label:

What if your website can increase the number of conversions and improve customer satisfaction?

Make an appointment with a professional consultant to communicate!

* Shangpin professional consultant will contact you as soon as possible

Disclaimer

Thank you very much for visiting our website. Please read all the terms of this statement carefully before you use this website.

1. Part of the content of this site comes from the network, and the copyright of some articles and pictures involved belongs to the original author. The reprint of this site is for everyone to learn and exchange, and should not be used for any commercial activities.

2. This website does not assume any form of loss or injury caused by users to themselves and others due to the use of these resources.

3. For issues not covered in this statement, please refer to relevant national laws and regulations. In case of conflict between this statement and national laws and regulations, the national laws and regulations shall prevail.

4. If it infringes your legitimate rights and interests, please contact us in time, and we will delete the relevant content at the first time!

Contact: 010-60259772
E-mail: [email protected]

Communicate with professional consultants now!

  • National Service Hotline

    400-700-4979

  • Beijing Service Hotline

    010-60259772

Please be assured to fill in the information protection
Online consultation

Disclaimer

Thank you very much for visiting our website. Please read all the terms of this statement carefully before you use this website.

1. Part of the content of this site comes from the network, and the copyright of some articles and pictures involved belongs to the original author. The reprint of this site is for everyone to learn and exchange, and should not be used for any commercial activities.

2. This website does not assume any form of loss or injury caused by users to themselves and others due to the use of these resources.

3. For issues not covered in this statement, please refer to relevant national laws and regulations. In case of conflict between this statement and national laws and regulations, the national laws and regulations shall prevail.

4. If it infringes your legitimate rights and interests, please contact us in time, and we will delete the relevant content at the first time!

Contact: 010-60259772
E-mail: [email protected]