cookie 最近浏览记录(中文escape转码)

history.js

/**
*pro_id: 产品id 
*brand_name : 品牌
*pro_name : 产品id 
*price : 价格
* catalog : 机型
* img : 图片
*file_name : 文件名
*/
var addHistory=function(pro_id,brand_name,pro_name,price,catalog,img,file_name){ 
    stringCookie=getCookie('history');
    var stringHistory=""!=stringCookie?stringCookie:"{history:[]}";
    var json=new JSON(stringHistory);
    var pro_ids = '' ;
    jQuery.each(json['history'],function(i,val){
    	pro_ids+=json['history'][i].pro_id+"," ;
    }) ;
    if(jQuery.trim(pro_id)=='' || pro_ids.indexOf(pro_id)==-1){
    	    var e="{pro_id:"+pro_id+",brand_name:'"+brand_name+"',pro_name:'"+pro_name+"',price:'"+price+"',catalog:'"+catalog+"',img:'"+img+"',file_name:'"+file_name+"'}";
		    json['history'].push(e);   //添加一个新的记录
		    setCookie('history',json.toString(),30);
    }
}
//显示历史记录
var DisplayHistory=function(){
    var p_ele=document.getElementById('history');
     while (p_ele.firstChild) {
      p_ele.removeChild(p_ele.firstChild);
     }

    var historyJSON=getCookie('history');
    var json=new JSON(historyJSON);
    var displayNum=6;
    for(i=json['history'].length-1;i>=0;i--){
        addLi(json['history'][i]['pro_id'],json['history'][i]['brand_name'],json['history'][i]['pro_name'],json['history'][i]['price'],json['history'][i]['catalog'],json['history'][i]['img'],json['history'][i]['file_name'],"history");
        displayNum--;
        if(displayNum==0){break;}
    }
}
//添加一个cookie   
var addLi=function(pro_id,brand_name,pro_name,price,catalog,img,file_name,pid){
    var a=document.createElement('a');
    var href='/proDetail/'+file_name;
    a.setAttribute('href',href);
    a.setAttribute("target","_blank") ;
    jQuery(a).html("<img src='"+unescape(img)+"' οnerrοr="+"this.src='/images/nopic.gif'"+" width='90' height='50' /><h3> "+unescape(brand_name+pro_name+catalog)+"</h3><span class='price'>"+unescape(price)+"</span>") ;
    var li=document.createElement('li');
    li.appendChild(a);
    jQuery(li).appendTo("#"+pid) ;
}
//添加cookie
var setCookie=function(c_name,value,expiredays)
{
    var exdate=new Date()
    exdate.setDate(exdate.getDate()+expiredays)
    cookieVal=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";path=/;expires="+exdate.toGMTString());
    document.cookie=cookieVal;
}
//获取cookie
function getCookie(c_name)
{
    if (document.cookie.length>0)
      {
      c_start=document.cookie.indexOf(c_name + "=")
      if (c_start!=-1)
        { 
        c_start=c_start + c_name.length+1 
        c_end=document.cookie.indexOf(";",c_start)
        if (c_end==-1) c_end=document.cookie.length
        return unescape(document.cookie.substring(c_start,c_end))
        } 
      }
    return ""
}
// 清除cookie 
function DeleteCookie(){
	 setCookie('history',"{history:[]}",30);
}

json.js

var JSON = function(sJSON){
 this.objType = (typeof sJSON);
if(this.objType=='string' && ''==sJSON){
      sJSON = '{history:[]}' ;
}
    this.self = [];
    (function(s,o){
    	for(var i in o){
    		o.hasOwnProperty(i)&&(s[i]=o[i],s.self[i]=o[i])
    		};})(this,(this.objType=='string')?eval('0,'+sJSON):sJSON);
}
JSON.prototype = {
    toString:function(){
        return this.getString();
    },
    valueOf:function(){
        return this.getString();
    },
    getString:function(){
        var sA = [];
        (function(o){
            var oo = null;
            sA.push('{');
            for(var i in o){
                if(o.hasOwnProperty(i) && i!='prototype'){
                    oo = o[i];
                    if(oo instanceof Array){
                        sA.push(i+':[');
                        for(var b in oo){
                            if(oo.hasOwnProperty(b) && b!='prototype'){
                                sA.push(oo[b]+',');
                                if(typeof oo[b]=='object') arguments.callee(oo[b]);
                            }
                        }
                        sA.push('],');
                        continue;
                    }else{
                        sA.push(i+':\''+oo+'\',');
                    }
                    if(typeof oo=='object') arguments.callee(oo);
                }
            }
            sA.push('},');
        })(this.self);
        return sA.slice(0).join('').replace(/\[object object\],/ig,'').replace(/,\}/g,'}').replace(/,\]/g,']').slice(0,-1);
    },
    push:function(sName,sValue){
        this.self[sName] = sValue;
        this[sName] = sValue;
    }
}
加一个cookie
addHistory("<%=uuid%>",escape("<%=factoryname%>"),escape("<%=name%>"),escape("<%=price%>"),escape("<%=catalogname%>"),escape("<%=img%>"),escape("<%=file_name%>"));
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值