从历史cookie中省略某些页面
omit certain pages from history cookie
我使用这个脚本将最近访问的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数组,或者你可以在页面中放一些东西,让脚本知道不保存该页面?…
HTML:函数saveHistory () {If ($('.no-save-history'))返回false;/* */}
& lt;Div id="history" class="no-save-history">
相关文章:
- 在jquery中为显示/隐藏设置cookie
- 按下按钮时保存cookie
- window.location替换并传递URL历史记录条目中的变量
- Javascript历史记录转换为php行
- 如何在Analytics.js中始终了解最新的cookie过期时间
- php httponly cookie在浏览器关闭时被删除
- 浏览器何时记录历史记录
- 如何在提交表单时将PHP变量传递到Javascript cookie中
- CORS-服务器端cookie没有保存在chrome浏览器上
- 如何为后台更改程序代码设置cookie
- 如何从另一个域加载cookie
- 流路由器流星的历史
- 使用jquery cookie的第三方cookie
- 无法在基于Cordova的应用程序中读取Set Cookie标头
- 如何使用Node.js脚本从Rally获取用户的修订历史
- 如何在Javascript中将单选按钮值保存到cookie中
- 输入类型按钮返回历史记录并返回顶部
- cookie加载事件页面重定向
- jquery cookie,在清除浏览器历史记录后仍然设置
- 从历史cookie中省略某些页面