我的 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.unload
event
$(window).unload(function() {
$.cookies.del('myCookie');
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)