In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to use JavaScript to record the number of website visits". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to use JavaScript to record the number of website visits.
We know that Cookie records the information of users who visit your site, and it resides on the user's hard disk. If the user returns to your site again, the cookie will be sent back to your server together, so that you can count and process the information of repeated visitors. Both IE4 and NS4 browsers provide support for Coo kie and allow us to manipulate them with Javascript or VBscript.
To get a brief idea of how Cookie reads and writes, take a look at the following example.
Write Cookie:
Function setCookie ()
/ / create a function to set Cookie
{var the_visits = 1;
/ / initialize VISIT, that is, the number of visits is 1
Var the_cookie = "3Ware=uservisits:"
+ escape (the_visits)
/ / add your own identifier and use the escape function to encode the Cookie
[xss_clean] = the_cookie;// writes to Cookie
}
In this way, a string 3Ware=uservisits:1 will be generated, which means that a Cookie named 3Ware is saved to the hard disk, and the value of the Cookie is uservisits:1. When we read Cookie, we just need to look for the Cookie whose name is 3Ware, and then decode it with unescape to read out the number of visits.
Read Cookie:
Function readCookie ()
{var the_cookie = [xss_clean];
/ / get the cookie value that has been written
Var broken_cookie = the_cookie.split (":")
/ / find the delimiter
Var the_visits = broken_cookie [1];
/ / read the last part of the delimiter
Var the_visits = unescape (the_visits)
/ / Decoding Cookie with unescape function
[xss_clean] ln ("Your visits is:"
+ the_visits); / / write out the number of visits
}
In this way, a string 3Ware=uservisits:1 is generated, which saves a Cookie named 3Ware to the hard disk, and the value of the Cookie is uservisits:1. When we read Cookie, we just need to look for the Cookie whose name is 3Ware, and then decode it with unescape to read out the number of visits.
Read Cookie:
Function readCookie ()
{var the_cookie = [xss_clean];
/ / get the cookie value that has been written
Var broken_cookie = the_cookie.split (":")
/ / find the delimiter
Var the_visits = broken_cookie [1];
/ / read the last part of the delimiter
Var the_visits = unescape (the_visits)
/ / Decoding Cookie with unescape function
[xss_clean] ln ("Your visits is:"
+ the_visits); / / write out the number of visits
}
Finally, add "setCookie (); readCookie ();" to the page to remember the number of visits.
However, this is only a basic principle, and the actual operation also involves the path where the Cookie is stored, when it expires, where its effective scope is, and whether there is a number of visits. Taking into account the above problems, the actual procedure is as follows:
Function GookieVal (offset)
/ / get the decoded value of Cookie
{
Var endstr = [xss_clean].
IndexOf (";", offset)
If (endstr =-1)
Endstr = [xss_clean] .length
Return unescape ([xss_clean].
Substring (offset, endstr))
}
Function Gookie (name)
/ / get the original value of Cookie
{var arg = name + "="
Var alen = arg.length
Var clen = [xss_clean] .length
Var I = 0
While (I 2)? argv [2]: null
Var path = (argc > 3)? argv [3]: null
Var domain = (argc > 4)? argv [4]: null
Var secure = (argc > 5)? argv [5]: false
[xss_clean] = name + "=" +
Escape (value) + ((expires = = null)?
"": ("; expires=" + expires.toGMTString ())
+ (path = = null)? "":
("; path=" + path) + ((domain = = null)? ""
: ("; domain=" + domain))
+ (secure = = true)? "; secure": "")
}
Function Dookie (name)
{var exp = new Date ()
Exp.setTime (exp.getTime () 1)
Var cval = Gookie (name)
[xss_clean] = name + "=" + cval + ";
Expires= "+ exp.toGMTString ()
}
Var expdate = new Date ()
Expdate.setTime (expdate.getTime () +)
(24 * 60 * 60 * 1000 * 365)
If (! (visits = Gookie ("3wave")
{visits = 1
Sookie (3wave, visits, expdate, "/", null, false)
[xss_clean] ("this is your first visit to this site" + visits + ");}
Else {visits++;
Sookie (3wave, visits, expdate, "/", null, false)
[xss_clean] ("you have visited the station for the first time" + visits + ")
}
If (visits=2&&visits=4&&visits=6)
[xss_clean] ("it is the pillar of the small station, I am so touched!")
In judging the sentences expressed by the number of visits, you can change the words with your own personality according to the style of the website. I believe that if the visitor sees these words on your website, he will be very impressed. this will make your site more attractive to others.
Thank you for reading, the above is the content of "how to use JavaScript to record the number of website visits". After the study of this article, I believe you have a deeper understanding of how to use JavaScript to record the number of website visits, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.