当前位置:   article > 正文

javascript delete cookie

js delete cookie

<script language="javascript">
 function GetCookie (name) {  //取得名称为name的cookie值
        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;
    }
 function getCookieVal (offset) {       //取得项名称为offset的cookie值
  var endstr = document.cookie.indexOf (";", offset);  
  if (endstr == -1)
   endstr = document.cookie.length;  
   return unescape(document.cookie.substring(offset, endstr));
 } 
 function DeleteCookie (name) {  //删除名称为name的Cookie
  var exp = new Date();  
  exp.setTime (exp.getTime() - 1);  
  var cval = GetCookie (name);  
  document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString() + ";path=/;domain=.ask.jp"; 

// 有域名的时候加上path,domain,没有域名的时候不用加path,domain
    }
    function Clearcookie() {
  var temp=document.cookie.split(";");
  var i;
  var ts;
  for (i=0;i<temp.length;i++)   
  {
   ts=temp[i].split("=")[0];
   DeleteCookie(ts);    
  }
 }
 function goToSignUpNotCookie(){
  Clearcookie();
  top.window.location="<bean:message bundle='const' key='http.domain.name'/>signUpInit.do?goto=banaKurara";
 }
</script>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/149721
推荐阅读
相关标签
  

闽ICP备14008679号