当前位置:Gxlcms > JavaScript > js实现浏览历史记录示例_javascript技巧

js实现浏览历史记录示例_javascript技巧

时间:2021-07-01 10:21:17 帮助过:43人阅读

先必须要引用一个js jquery.cookie.js

1,首先写入jsCookied
代码如下:

//浏览记录 写入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:"/"});
}
//浏览记录 写入JSCookied 结束

2,然后再读取Cookied
代码如下: