简体   繁体   English

为什么Cookie未被删除?

[英]Why is cookie not getting deleted?

I have created a cookie through javascript. 我已经通过javascript创建了一个cookie。 Which I want to clear out on logout. 我要在注销时清除。 The site is running on SSL. 该站点正在SSL上运行。 Following is the JS code that I have used for the cookie creation and deletion purpose. 以下是我用于cookie创建和删除目的的JS代码。 Note that it is a plain cookie (non http, non secure and as simple as it can be). 请注意,它是一个普通的cookie(非http,非安全且尽可能简单)。 Below is the function which is creating the cookie, which creates cookie just fine, this cookie is a session cookie and all other details are parameters used to create this cookie. 下面是创建cookie的函数,该函数创建cookie很好,此cookie是会话cookie,所有其他详细信息都是用于创建此cookie的参数。

login: function () {
"use strict";
var cookieKeys, cookieValues;
if (cookieExists(this.systemPolicyCookie)) {
    cookieKeys = this.activeUserCookieName + '=';
    cookieValues = 'Email=' + this.activeUserCookieValues.Email + '&';
    cookieValues += 'UserId=' + this.activeUserCookieValues.UserId;
    cookieKeys += encodeURIComponent(cookieValues) + cookieDelimiter;
    cookieKeys += 'domain=' + this.activeUserCookieDomain + cookieDelimiter + cookiePath;
    document.cookie = cookieKeys;
    document.location.href = document.location.protocol + '//' + document.location.host + '/User/Landing/';
} else {
    alert('System policies are missing, please login online.');
    document.location.href = document.location.protocol + '//' + document.location.host;
}

}, },

The following code block should delete the cookie created above, which doesn't work. 以下代码块应删除上面创建的cookie,该cookie无效。

logout: function () {
"use strict";
var cookies = cookieArray(),
    name;
for (name in cookies) {
    if (name != null && (this.systemPolicyCookie.toString()
        .toLowerCase() !== name.toString()
        .toLowerCase())) {
        document.cookie = name + '="";-1; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT';
    }
}
document.location.href = document.location.protocol + '//' + document.location.host;

}, },

The cookieArray() function returns a list of all cookies, which is as follows: cookieArray()函数返回所有cookie的列表,如下所示:

var cookieArray = function () {
"use strict";
var cookies = {},
counter,
split,
nameValue;
if (document.cookie && document.cookie !== '') {
    split = document.cookie.split(';');
    for (counter = 0; counter < split.length; counter++) {
        nameValue = split[counter].split("=");
        nameValue[0] = nameValue[0].replace(/^ /, '');
        cookies[decodeURIComponent(nameValue[0])] = decodeURIComponent(nameValue[1]);
    }
}
return cookies;

Could you help me get the cookie deletion code working, otherwise I will have to get the browser closed (bad Ux) 您能帮我使cookie删除代码正常工作吗,否则我将不得不关闭浏览器(Ux错误)

What browser are you using?? 你使用的是什么浏览器??

As far as I know, IE caches the cookies, therefore they will be deleted until you restart your browser. 据我所知,IE会缓存cookie,因此它们将被删除,直到您重新启动浏览器为止。 I'm not sure if FireFox or Chrome do the same 我不确定FireFox或Chrome是否会执行相同的操作

Have you tried testing your code in Chrome and/or FireFox?? 您是否尝试过在Chrome和/或FireFox中测试代码?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM