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; } function setCookie (name, value) { var exp = new Date(); exp.setTime(exp.getTime() + 864000000); //一天换算成毫秒:24 * 60 * 60 * 1000 = 864000000 document.cookie = name + "=" + value + "; expires=" + exp.toGMTString(); } function history_show(){ var history_info = getCookie("history_info"); var content = ""; if(history_info != null){ history_arg = history_info.split("--michael.tsai--"); for(var i=0; i < 30; i++){ //最多显示 30 条历史记录 if(history_arg[i] != null && history_arg[i] != 'null'){ var currentHistory = history_arg[i].split("--cai.shuliang--"); var limit_len = 12;//显示 10 个汉字字符,或 20 个英文字母或数字 var finalLength = getLength(currentHistory[0], limit_len); var displayText = currentHistory[0].substr(0, finalLength); if(getLeftChars(currentHistory[0], limit_len) < 0){ displayText += "..."; } content += ("" + displayText + "
"); } document.getElementById("history").innerHTML = content; } } else{ document.getElementById("history").innerHTML="目前没有任何浏览纪录"; } } //写入 cookie function writeCookie(type){ var title = document.title.split(" | ")[0]; title = type + ":" + title; var href = document.location; var currentHistory = title + "--cai.shuliang--" + href + "--michael.tsai--"; old_info = getCookie("history_info"); var insert = true; if(old_info != null){ var old_link = old_info.split("--michael.tsai--"); for(var j=0; j < old_link.length; j++){ if(old_link[j].indexOf(title) != -1){ insert = false; } if(old_link[j] == "null"){ break; } } } if(insert){ currentHistory += getCookie("history_info"); setCookie("history_info",currentHistory); } }