我的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');
});
}
});
}
Run Code Online (Sandbox Code Playgroud)