在jquery

时间:2015-11-10 23:55:40

标签: jquery html cookies

我想删除Cookie,以防登录用户离开网站时关闭标签/浏览器而不登出。我的问题是,即使我用F5刷新页面或点击“重置”按钮,它也会运行注销功能并将我发送到登录页面。有什么想法吗?

$(window).on("beforeunload", function() {

        logout();

})


function logout(){

var sessionArr = getSessionArr();


$.ajax({
    type: "POST",
    url: "php/logout.php",
    data: "sessionArray=" + sessionArr,
    dataType: "json",
    success: function (msg, string, jpXHR) {
        alert("cookies sent");
    }
});
Cookies.remove('user', { expires:null, path: '' }); // removed!
window.location.href = "http://localhost/CookieSite/login.html";

}

1 个答案:

答案 0 :(得分:0)

简短回答:这个问题没有解决办法。您无法检测窗口是否已关闭。