Home > Web Front-end > JS Tutorial > Use cookies to save website history browsing history example code_javascript skills

Use cookies to save website history browsing history example code_javascript skills

WBOY
Release: 2016-05-16 18:23:24
Original
1460 people have browsed it

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:

Copy code The code is as follows:

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:

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template