...所有Cookies内容的操作,如何实现,是所有的Cookies内容,谢谢
发布网友
发布时间:2022-04-29 21:39
我来回答
共1个回答
热心网友
时间:2022-04-25 06:20
var cookies = document.cookie.split(";");
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i];
var eqPos = cookie.indexOf("=");
var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/";
}
if(cookies.length > 0)
{
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i];
var eqPos = cookie.indexOf("=");
var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
var domain = location.host.substr(location.host.indexOf('.'));
document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; domain=" + domain;
}
}
js实现追问
如上图,我要实现这样的清除的效果,通过代码,但我不知道为什么var cookies = document.cookie.split(";");取出来的null, 不同的浏览器我都试过了,