如何删除选项卡上关闭的jQuery cookie [英] how to delete jquery cookie on tab close

查看:64
本文介绍了如何删除选项卡上关闭的jQuery cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的cookie工作正常,我没有提到日期,因此当关闭浏览器窗口时,cookie被删除.

My cookie is working fine i m not mentioning date so when the browser window is closed the cookie is deleted.

但是当我关闭浏览器窗口中的选项卡时,cookie不会被删除,并且在我打开网站时会打开相同的cookie状态页面

but when i close a tab in a browser window the cookie is not deleted and open the same preserved cookie state page when i open the website

如何在用户关闭浏览器"选项卡时删除cookie?

How to delete a cookie when a user closes a Browser tab ?

下面是我的代码

$(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');
            });
        }   
    });
}

推荐答案

您必须在 .unload 事件

$(window).unload(function() {
   $.cookies.del('myCookie');
});

这篇关于如何删除选项卡上关闭的jQuery cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆