In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, I would like to share with you how to create cookie in JavaScript to store the names of visitors. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look.
When the visitor arrives at the web page for the first time, he will be asked to fill in his name. The name is then stored in cookie.
The next time the visitor arrives on the same page, he will receive a welcome message.
For example, we will create three JavaScript functions:
Function that sets the value of cookie
Function that gets the value of cookie
A function that checks the value of cookie
Set the function of cookie
First, we create a function that stores the visitor's name in the cookie variable:
Example
Function setCookie (cname, cvalue, exdays) {
Var d = new Date ()
D.setTime (d.getTime () + (exdays*24*60*60*1000))
Var expires= "expires=" + d.toUTCString ()
[xss_clean] = cname + "=" + cvalue + ";" + expires + "; path=/"
}
Examples explain:
The above function takes the name of cookie (cname), the value of cookie (cvalue), and the number of days it takes to know that cookie expires (exdays).
This function sets the cookie by adding the cookie name, the cookie value, and the expired string.
Get the function of cookie
Then we create a function that returns the value of the specified cookie:
Example
Function getCookie (cname) {
Var name = cname + "="
Var decodedCookie = decodeURIComponent ([xss_clean])
Var ca = decodedCookie.split (';')
For (var I = 0; I
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.