In the following code, pay attention to the use of multiple addition judgments of cookies. Friends who are learning how to operate cookies are well worth a look.
Core code:
function glog(evt){
evt=evt?evt:window.event;
var srcElem=(evt.target)?evt.target:evt.srcElement;
try{
while(srcElem.parentNode&&srcElem!=srcElem. parentNode){
if(srcElem.tagName&&srcElem.tagName.toUpperCase()=="A"){
linkname=srcElem.innerHTML;
address=srcElem.href "|";
wlink= linkname " " address;
old_info=getCookie("history_info");
var insert=true;
if(old_info==null){//Determine whether the cookie is empty
insert=true;
}
else{
var old_link=old_info.split("|");
for(var j=0;j<=5;j ){
if(old_link[j ].indexOf(linkname)!=-1)
insert=false;
if(old_link[j]=="null")
break;
}
}
if (insert){
wlink =getCookie("history_info");
setCookie("history_info",wlink);
history_show().reload();
break;
}
else
{
var old_link1=old_info.split("|");
var length=old_link1.length
var newcookie=''
for(var j=0;length<=6?j<=length-1:j<=5;j ){
if(old_link1[j].indexOf(linkname)==-1)
{
if(j==length-1||j==5)
{
newcookie=newcookie old_link1[j]
}
else
{
newcookie=newcookie old_link1[j ] '|'
}
}
}
newcookie=wlink newcookie
setCookie("history_info",newcookie);
history_show().reload();
break;
}
}
srcElem = srcElem.parentNode;
}
}
catch(e){}
return true;
}
Complete effect demonstration code:
Statement: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