js清空cookie

// js 遍历所有Cookie
function foreach()
{
  var strCookie=document.cookie;
  var arrCookie=strCookie.split("; "); // 将多cookie切割为多个名/值对
  for(var i=0;i0)
  DelCookie(arr[0]);
}
   
}
function GetCookieVal(offset)
   
{
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return decodeURIComponent(document.cookie.substring(offset, endstr));
}
function DelCookie(name)
{
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires="+ exp.toGMTString();
}
 
function GetCookie(name)
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return GetCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}

  转载自:http://blog.csdn.net/xiaona1047985204/article/details/6700931

你可能感兴趣的:(js清空cookie)