我正在尝试清理一些重复的Cookie。最初的问题是,这些cookie仅限于设置它们的当前子域。我们将这些cookie的范围更改为域的全局范围。这给我们留下了不同域的重复cookie。我想删除这些域范围的cookie但代码不起作用,除非" hostonly"标志是手动停用的?我认为,如果设置cookie的同一域名,提供代码删除cookie,那么我就不必担心这个问题" hostOnly"旗?看起来不是真的吗?任何人都明白为什么这不能删除cookie以及如何/如果我可以?
try{
function clearCookie(name, domain, path){
var domain = domain || document.domain;
var path = path || "/";
document.cookie = name + "=; expires=Thu, 01 Jan 1970 00:00:01 GMT; domain=" + domain + "; path=" + path;
};
clearCookie("visitCount","www.mysite.com","/");
clearCookie("lastVisit","www.mysite.com","/");
clearCookie("visitedPreviously","www.mysite.com","/");
clearCookie("navElemName","www.mysite.com","/");
clearCookie("s_uniqueUserID","www.mysite.com","/");
clearCookie("pcidSet","www.mysite.com","/");
document.cookie = "cookiesCleaned=1; path=/; domain=.mysite.com";
}catch (e) {}