You must first reference a js jquery. cookie. js
1. Write the jsCookied
Copy codeThe Code is as follows:
// The browsing record is written to JSCookied.
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 :"/"});
}
// The browsing record is written to JSCookied and ends.
2, and then read Cookied
Copy codeThe Code is as follows:
<Script type = "text/javascript" charset = "UTF-8">
// Read the 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] + '"> </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] + '"> let's see </a> </div> ');
}
Xhtml. push ('<div class = "tr"> <a href = "javascript: clearcookied ();"> clear records </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] + '"> </a> <p> ¥' + hc. split ("|") [3] + '</p> </div> ');
Xhtml. push ('<div class = "otherInfo clearfix"> <span> sold <B>' + hc. split ("|") [4] + '</B> </span> <a href = "' + hc. split ("|") [2] + '"> let's see </a> </div> ');
Xhtml. push ('<div class = "tr"> <a href = "javascript: clearcookied ();"> clear records </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>