【发布时间】:2012-02-27 19:20:22
【问题描述】:
我的 cookie 工作正常,我没有提到日期,所以当浏览器窗口关闭时,cookie 会被删除。
但是当我关闭浏览器窗口中的选项卡时,cookie 不会被删除,并且在我打开网站时会打开相同的保留 cookie 状态页面
当用户关闭浏览器选项卡时如何删除 cookie?
下面是我的代码
$(document).ready(function(){
var href = $.cookie("activeElementHref");
if(href!==null)
{
setContainerHtml(href);
};
$('nav ul li a').click(function(e){
e.preventDefault();
href= $(this).attr('href');
$.cookie("activeElementHref", href)
setContainerHtml(href);
});
});
$(window).unload(function() {
$.cookies("activeElementHref",null);
});
function setContainerHtml(href) {
$.ajax({
type: "POST",
url: "baker.php",
data:{send_txt: href},
success: function(data){
$('#aside-right, #intro').css('display','none');
$('#main-content').fadeOut('10', function (){
$('#main-content').css('width','700px');
$('#main-content').css('margin','-30px 0 0 100px');
$('#main-content').html(data);
$('#main-content').fadeIn('8000');
});
}
});
}
【问题讨论】:
-
您找到解决方案了吗?我有同样的问题,我只需要在标签关闭时删除 cookie,而不是在页面刷新时删除
标签: javascript jquery cookies