1
我已經通過javascript創建了一個cookie。我想在註銷時清除它。該網站正在使用SSL。以下是我用於創建和刪除cookie的JS代碼。請注意,它是一個普通的cookie(非http,非安全且儘可能簡單)。下面是創建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;
}
},
下面的代碼塊應該刪除上面創建的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;
},
的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;
你能不能幫我把Cookie刪除代碼的工作,否則我將不得不關閉瀏覽器(壞Ux)
是的FF是我的主要瀏覽器在這裏。我已經在Chrome,FF,IE上測試過它。 – Rahul