Jquery. cookie. js is used to display the history of web pages that have been browsed. jquery. cookie. js

Source: Internet
Author: User

Jquery. cookie. js is used to display the history of web pages that have been browsed. jquery. cookie. js

This article uses the cookie plug-in to obtain the user's browsing history and display the user's recent browsing history on the page.

Add the following js

<Script type = "text/javascript" src = "js/jquery. js "> </script> <script type =" text/javascript "src =" js/jquery. cookie. js "> </script> <script type =" text/javascript "> $ (function () {var art_title = $ (" title ").html (); var art_url = document. URL; var history; var json = "["; // json1 is the first json after the cookie is injected for the first time. "This is not an array yet." handle var json1 with dots and planes; var canAdd = true; // var json1 = eval ("({sitename: 'dreamdu', sitedate: new Date (1980 , 12, 17, 12, 0, 0)}) "); if (! $. Cookie ("history") {// initialize history =$ for the first time. cookie ("history", "{title: \" "+ art_title +" \ "" + ", url: \" "+ art_url + "\"}");} else {// history already exists = $. cookie ("history"); json1 = eval ("(" + history + ")"); $(json1 ). each (function () {if (this. title = art_title) {canAdd = false; return false ;}}) if (canAdd) {$ (json1 ). each (function () {json = json + "{\" title \ ": \" "+ this. title + "\", \ "url \": \ "" + this. url + "\"}, ";}) json = json +" {\ "title \": \ "" + art_title + "\", \ "url \": \ "" + art_url + "\"}] "; $. cookie ("history", json, {expires: 1}) ;}}) </script>

Add the following js

<script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript" src="js/jquery.cookie.js"></script> <script type="text/javascript"> $(function(){  if($.cookie("history")){ var json = eval("("+$.cookie("history")+")");  var list ="";  $(json).each(function(){  list = list + "<li><a href='"+this.url+"' target='_blank'>"+this.title+"</a></li>";  alert(this.url); }) $("#list").html(list);; }  });  </script> 

The above content is shared with you through Jquery. cookie. js to demonstrate the history of Web browsing.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.