【发布时间】:2016-05-27 19:45:33
【问题描述】:
我正在使用 jQuery Cookie 插件 (https://github.com/carhartl/jquery-cookie),但在我的网站上的不同页面上保存我的 cookie 时遇到问题。
我有一段内容显示在每个页面上,一旦隐藏它就会像这样设置 cookie(对所有变量表示歉意,它们根本不相关:
// Binds the close event to the button.
$alert.on('click', function(e) {
$alertWrap.fadeOut();
// Sets the breaking-delete cookie to yes.
$.cookie('breaking-bar-delete', 'yes', {expires: 7 });
});
当初始脚本触发时,它会检查 cookie 是否存在:
// If the current bar is not supressed and they are not in the editor, and they do not have a closed cookie it will setup the bar.
if ($.cookie('breaking-bar-delete') == undefined) {
$alert.css("display","block");
}
// If there's no news, or they have the closed cookie for the current bar it hides it by default.
if ($.cookie('breaking-bar-delete') == 'yes') {
$alert.parent().css("display","none");
}
现在这适用于您隐藏栏的路径,因此如果您刷新它就不会重新显示。但是,如果您使用不同的路径访问网站的某个部分,它不会检测到 cookie 并显示内容。
在我最初提供 cookie 时是否可以设置某种配置,以便它在我网站上的所有页面中持续存在?
【问题讨论】:
标签: javascript jquery cookies