添加cookie最近浏览过的5职位

关键字: cookie

if(document.all){ //ie
  window.attachEvent('onload',readCookie);

}else{ //ff
window.addEventListener('load',readCookie,false);

}


//添加cookie最近浏览过的5职位
function setCookie(name, value){
  var date = new Date();//new 出当前时间
  date.setTime(date.getTime()-1);//当前时间减一,表示过去时间
  var broken_Cookie = document.cookie.split(";");//获得cookie的内容并用分号分开,(分号是cookie自己的分隔符)
// alert(broken_Cookie.length);
value = encodeURI(value);//如果遇到汉字,要对其进行转码
  if(broken_Cookie.length > 5) {//如果分割出的数组>5删除第一条
   var kuku = ""+broken_Cookie[0].split("=")[0]+"="+value+";expires="+date.toGMTString();+"";//
   document.cookie =kuku;
  }
  var Cookie = ""+name+"="+value+"";
  document.cookie =Cookie;
}
//显示cookie
function readCookie(){//将cookie的内容读到页面
  var beforeCompany = document.getElementById("beforeCompany");
  var Cookie = document.cookie;
  var broken_Cookie =Cookie.split(";");
  for(var i = 0; i < broken_Cookie.length; i++) {
   var content =  broken_Cookie[i];
//beforeCompany.innerHTML="<li><a href='/HereB2B/app/job/jobshow/"+index.split('e')[1]+".htm' title='"+text+"'>"+text.substr(0,17)+"</a></li>";
   var index = content.indexOf("corpName");
   if(index == 0 || index == 1) {
    var li = document.createElement("li");
    var text = content.split("=")[1];
    text = decodeURI(text);
    var index = content.split("=")[0];
    li.innerHTML = "<a href='/HereB2B/app/job/jobshow/"+index.split('e')[1]+".htm' title='"+text+"'>"+text.substr(0,17)+"</a>";
    beforeCompany.appendChild(li);
   }  
  }
}

你可能感兴趣的:(IE)