how to delete cookies which created in server side using javascript (In Processing)

本文详细讨论了如何在Internet Explorer 8中解决Cookie问题,包括检查客户端和服务器端的域名和路径设置是否一致,确认Cookie是否为安全或非安全,以及怀疑服务器或客户端时间同步问题的可能性。通过示例代码展示了如何设置、读取和删除Cookie,并提供了一个清除特定Cookie的函数。

Dicussing....

 

 

The following script is only works in IE8

 

  • Have you checked the client-side and server-side cookie domains and paths to ensure they're the same?
  • Is one cookie secure and the other not?
  • Other than that, I would suspect server/client clock sync issues, as Erlend suggests.
  • http://stackoverflow.com/questions/55860/why-cant-i-delete-this-cookie

<html>
<head>
<script type="text/javascript" language="javascript">
    //******************************************************************************************
    // To add cookie information to the HTTP header need to use the following Syntax:
    //
    // document.cookie = "name=value; expires=date; path=path;domain=domain; secure";
    //
    // This function sets a client-side cookie as above.  Only first 2 parameters are required
    // Rest of the parameters are optional. If no CookieExp value is set, cookie is a session cookie.
    //******************************************************************************************

    function setCookie(CookieName, CookieVal, CookieExp, CookiePath, CookieDomain, CookieSecure)
    {
         var CookieText = escape(CookieName) + '=' + escape(CookieVal); //escape() : Encodes the String
        CookieText += (CookieExp ? '; EXPIRES=' + 'Thu, 01-Jan-1970 00:00:01 GMT' : '');
        CookieText += (CookiePath ? '; PATH=' + CookiePath : '');
        CookieText += (CookieDomain ? '; DOMAIN=' + CookieDomain : '');
        CookieText += (CookieSecure ? '; SECURE' : '');
       
        document.cookie = CookieText;
    }

    // This functions reads & returns the cookie value of the specified cookie (by cookie name)
    function getCookie(CookieName)
    {
         var CookieVal = null;
        if(document.cookie)       //only if exists
        {
               var arr = document.cookie.split((escape(CookieName) + '='));
               if(arr.length >= 2)
               {
                   var arr2 = arr[1].split(';');
                   CookieVal  = unescape(arr2[0]); //unescape() : Decodes the String
               }
        }
        return CookieVal;
    }

    // To delete a cookie, pass name of the cookie to be deleted
    function deleteCookie(CookieName)
    {
         var tmp = getCookie(CookieName);
        if(tmp)
        {
            setCookie(CookieName,tmp,(new Date(1))); //Used for Expire
        }
    }

alert(getCookie('LOGGEDIN_SESSION'));
setCookie("LOGGEDIN_SESSION", "", -1);
alert(getCookie('LOGGEDIN_SESSION'));


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;
};

alert(document.domain)

clearCookie('LOGGEDIN_SESSION');
alert(getCookie('LOGGEDIN_SESSION'));
 </script>
</head>
<body>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值