从历史cookie中省略某些页面

omit certain pages from history cookie

本文关键字:历史 cookie 中省      更新时间:2023-09-26

我使用这个脚本将最近访问的10个页面的用户历史记录存储到cookie中。到目前为止,我已经获得了使用文档显示cookie数据的脚本。标题和url。

我的问题是添加页面跳过功能的最简单方法是什么,这将使我从添加到历史cookie中省略某些页面?我试过的所有方法都不奏效,因为这有点超出我的知识范围。

谢谢你的时间和帮助。

JS:

(function($){
var history;
function getHistory() {
    var tmp = $.cookie("history");
    if (tmp===undefined || tmp===null) tmp = "";
    if ($.trim(tmp)=="") tmp = [];
    else tmp = tmp.split("||");
    history = [];
    $.each(tmp, function(){
        var split = this.split("|");
        history.push({
            title: split[0],
            url: split[1]
        });
    });
}
function saveHistory() {
    var tmp = [];
    $.each(history, function(){
        tmp.push(this.title+"|"+this.url);
    });
    $.cookie("history",tmp.join("||"),{ expires: 60, path: "/" });
}
function addToHistory(title,url) {
    var newHistory = []
    $.each(history, function(){
        if (this.url!=url) newHistory.push(this);
    });
    history = newHistory;
    if (history.length>=10) {
        history.shift();
    }
    history.push({
        title: title,
        url: url
    });
    saveHistory();
    writeHistory();
}
function writeHistory() {
    var list = $("<ul />");
    $.each(history, function() {
        var element = $("<li />");
        var link = $("<a />");
        link.attr("href",this.url);
        link.text(this.title);
        element.append(link);
        list.append(element);
    });
    $("#history").empty().append(list);
}
$(document).ready(function(){
    getHistory();
    var url = document.location.href;
    var split = url.split("#");
    var title;
    if (split.length > 1) {
        title = $("#"+split[1]).text();
    } else {
        title = document.title;
    }
    if (title===undefined || title===null || $.trim(title)=="") title = url;
    addToHistory(title,url);
    url = split[0];
    $("a[href^='#']").click(function(){
        var link = $(this);
        var href = link.attr("href");
        var linkUrl = url+href;
        var title = $(href).text();
        if (title===undefined || title===null || $.trim(title)==="") title = linkUrl;
        addToHistory(title,linkUrl);
    });
});
})(jQuery);
HTML:

<div id="history"></div>

有几种方法可以做到这一点…你可以保留一个不保存的url数组,或者你可以在页面中放一些东西,让脚本知道不保存该页面?…

函数saveHistory () {If ($('.no-save-history'))返回false;/* */}

HTML:

& lt;Div id="history" class="no-save-history">