In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you about how to record the recent browsing history of users using Cookie and JSON. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
In some e-commerce websites, there is a "product browsing history" function, and some video and fiction websites can also record users' recent browsing history. The editor will use Cookie and JSON to explain how to implement this function.
Cookie can be used to record the client user ID, password, browsed web pages, stay time and other information, jQuery provides a cookie plug-in, it is very convenient to read and write cookie information, about the cookie plug-in, you can learn more about the previous articles on this site: use jQuery to operate Cookies.
The following is to use the cookie plug-in to get the user's browsing article history and display the user's most recent browsing history on the page. In order to cooperate with the explanation, I will take the blog article on this site as an example. After browsing the blog article on this site, the reader will record the title and URL address of the article he browsed. When he enters the demo page, he will show the 5 articles that the reader has recently browsed.
Basic process:
1. Get the details of the article, the title and address of the page article
2. Get the cookie information of browsing history and judge that if the browsing history of the current article already exists in the cookie of browsing history, no action will be taken.
3. If the browsing record of the current article does not exist in the cookie of the browsing history, the cookie information of the current article (article title and page address) is written into the cookie information of the browsing history. The written cookie information is in JSON data format and is easy to read.
4. Get the browsing history cookie information, traverse the JSON data, analyze and output the browsing history.
Detailed explanation
1. Make sure that the details page of the article you want to record your browsing history has been loaded into the jquery and cookie plug-ins. Get the article title and page address of the current article page:
Var art_title = $(".blog _ txt h3") .text (); / / article title var art_url = document.URL; / / page address
2. Get the user history browsing record. If the browsing history already exists, analyze the cookie information (JSON data format) of the historical record and get the record length.
Var canAdd = true; / / initially you can insert cookie information var hisArt = $.cookie ("hisArt"); var len = 0; if (hisArt) {hisArt = eval ("(" + hisArt+ ")"); len = hisArt.length;}
3. If the browsing history cookie information already exists, then traverse the cookie information, compare the current article title, if the current article title already exists in the cookie information, then abort the program and do nothing.
$(hisArt) .each (function () {if (this.title = = art_title) {canAdd = false; / / already exists, cannot insert return false;}})
4. If the current article does not exist in the browsing history cookie, you can insert the cookie information of the current article as in the browsing history cookie. At this point, you need to build the json data, combine the existing browsing record cookie and the cookie information of the current page into JSON data, and then write it to the browsing history through the $.cookie () method.
If (canAdd==true) {var json = "["; var start = 0; if (len > 4) {start = 1;} for
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.