Home Web Front-end JS Tutorial js implementation of browsing history example_javascript skills

js implementation of browsing history example_javascript skills

May 16, 2016 pm 04:51 PM

You must first reference a js jquery.cookie.js

1, first write jsCookied

Copy code code As follows:

//Browsing record written to JSCookied starts
var img=$("#ProductImgurl").attr("jqimg");
var name=$("# ProductDetail_ctl00_LabelName").text();
var url=location.href;
var price=$("#ProductDetail_ctl00_LabelShopPrice").text();
var sellcount=$("#ProductDetail_ctl00_lblSaleNumber"). text();
var hc=img "|" name "|" url "|" price "|" sellcount;
if($.cookie("history")!=null)
{
if($.cookie("history").indexOf(name)==-1)
{

$.cookie("history",hc "*" $.cookie("history "),{expires:8,domain:'.groupfly.com',path:"/"});
}
}
else
{
$.cookie("history ",hc,{expires:8,domain:'.groupfly.com',path:"/"});
}
//Write browsing history to JSCookied End

2. Then read Cookied
Copy code The code is as follows:

<script type= "text/javascript" charset="utf-8">
//Read cookied history
$(function(){

var hc=$.cookie("history") ;
if(hc!=null)
{
if(hc.indexOf("*")!=-1)
{
var splithtml=hc.split("*" );
var xhtml=new Array();
var hlength=splithtml.length;
if(parseInt(hlength)>4)
hlength=4;
for(var i =0;i<parseInt(hlength);i )
{
xhtml.push('<div class="tuijian"><div class="tjname"><a href=" ' splithtml[i].split("|")[2] '">' splithtml[i].split("|")[1].substr(0, 17) '</a></ div>');
xhtml.push('<div class="tjimga"><a href="' splithtml[i].split("|")[2] '">< img src="' splithtml[i].split("|")[0] '_160x160.jpg" alt="' splithtml[i].split("|")[1] '" /></ a><p>¥' splithtml[i].split("|")[3] '</p></div>');
xhtml.push('<div class=" otherInfo clearfix"><span>Sold<b>' splithtml[i].split("|")[4] '</b>pen</span><a href="' splithtml [i].split("|")[2] '">Look again</a></div></div>');
}
xhtml.push(' <div class="tr"><a href="javascript:clearcookied();">Clear record</a></div>');
$("#MyHistory") .append(xhtml.join(""));
}
else{
var xhtml=new Array();
xhtml.push('<div class="tuijian"> <div class="tjname"><a href="' hc.split("|")[2] '">' hc.split("|")[1].substr(0, 17 ) '</a></div>');
xhtml.push('<div class="tjimga"><a href="' hc.split("|")[2 ] '"><img src="' hc.split("|")[0] '_160x160.jpg" alt="' hc.split("|")[1] '" />< /a><p>¥' hc.split("|")[3] '</p></div>');
xhtml.push('<div class="otherInfo clearfix "><span>Sold<b>' hc.split("|")[4] '</b>Pen</span><a href="' hc.split("| ")[2] '">Look again</a></div></div>');
xhtml.push('<div class="tr">< a href="javascript:clearcookied();">Clear record</a></div>');
$("#MyHistory").append(xhtml.join(""));
}
}
else
{
$("#MyHistory").append("<li>No browsing history</li>");
}
});

function clearcookied()
{
$.cookie('history',null,{expires:1,domain:'.nrqiang.com'});
$("#MyHistory").html("<li>No browsing history</li>");
}
$(function() {
$("img" ).each(function(){$(this).attr("src",$(this).attr("original"));});
});
</script>
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Replace String Characters in JavaScript Replace String Characters in JavaScript Mar 11, 2025 am 12:07 AM

Replace String Characters in JavaScript

Custom Google Search API Setup Tutorial Custom Google Search API Setup Tutorial Mar 04, 2025 am 01:06 AM

Custom Google Search API Setup Tutorial

Example Colors JSON File Example Colors JSON File Mar 03, 2025 am 12:35 AM

Example Colors JSON File

8 Stunning jQuery Page Layout Plugins 8 Stunning jQuery Page Layout Plugins Mar 06, 2025 am 12:48 AM

8 Stunning jQuery Page Layout Plugins

10 jQuery Syntax Highlighters 10 jQuery Syntax Highlighters Mar 02, 2025 am 12:32 AM

10 jQuery Syntax Highlighters

Build Your Own AJAX Web Applications Build Your Own AJAX Web Applications Mar 09, 2025 am 12:11 AM

Build Your Own AJAX Web Applications

What is 'this' in JavaScript? What is 'this' in JavaScript? Mar 04, 2025 am 01:15 AM

What is 'this' in JavaScript?

10  JavaScript & jQuery MVC Tutorials 10 JavaScript & jQuery MVC Tutorials Mar 02, 2025 am 01:16 AM

10 JavaScript & jQuery MVC Tutorials

See all articles