document.onclick=glog;//使每一次页面的点击动作都执行glog函数
第2部分:Cookies的相关函数
//cookie的相关函数
//读取cookie中指定的内容
function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1) endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function getCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg) return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
//将浏览动作写入cookie
function setCookie (name, value) {
var exp = new Date();
exp.setTime (exp.getTime()+3600000000);
document.cookie = name + "=" + value + "; expires=" + exp.toGMTString();
}
第3部分:页面显示函数
function history_show()
{
var history_info=getCookie("history_info"); //取出cookie中的历史记录
var content=""; //定义一个显示变量
if(history_info!=null)
{
history_arg=history_info.split("_www.achome.cn_");
var i;
for(i=0;i<=5;i++)
{
if(history_arg[i]!="null")
{
var wlink=history_arg[i].split("+");
content+=("<font color=#ff000>↑</font>"+"<a href="+wlink[1]+" target=_blank>"+wlink[0]+"</a><br>");
}
document.getElementById("history").innerHTML=content;
}
}
else
{document.getElementById("history").innerHTML="对不起,您没有任何浏览纪录";}
代码差不多就是这些了 就为大家分析到这里 还有不足之处还请大家多多指教 下面可以运行代码查看效果