使用Javascript删除会话cookie [英] Delete session cookies by using Javascript
问题描述
我正在开发删除会话cookie的功能
I am working on a function to delete the session cookies
以下是源代码:
<script language="javascript">
window.onload = function ()
{
/* $.cookie('!lithiumSSO:tomtom.stage', null);
$.cookie('LiSESSIONID', null);*/
delete_cookie('LiSESSIONID');
delete_cookie('!lithiumSSO:tomtom.stage');
};
function delete_cookie ( cookie_name )
{
var cookie_date = new Date ( ); // current date & time
cookie_date.setTime ( cookie_date.getTime() - 1 );
document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
alert('name:' +cookie_name);
jQuery.cookie('LiSESSIONID', null); //Try to using jQuery
}
我可以设置一个弹出窗口显示名称:LiSESSIONID =; expires = Wed,02 Feb 2011 10:56:52 GMT。这比落后一小时。但是,当我使用firecookies时,我看到这个cookie仍然存在:
I can set got a pop up window displays name:LiSESSIONID=; expires=Wed, 02 Feb 2011 10:56:52 GMT. Which is one hour behind. However, when I use firecookies, i saw this cookie still exists:
LiSESSIONID
LiSESSIONID
7A10E3453B01DDFF934AC7AF71EAFEC3
forums.lithiumstage.tomtom.com
43 B
7A10E3453B01DDFF934AC7AF71EAFEC3
forums.lithiumstage.tomtom.com
43 B
/
会话
HttpOnly
有谁知道为什么我不能杀死cookie? jQuery函数状态表示undefined甚至我加载函数
Does anyone have an idea why i can not kill the cookies? jQuery function state said undefined even I load the function
谢谢
推荐答案
原因是因为设置了HttpOnly标志。这意味着只有服务器端代码才能修改此cookie。
The reason is because the HttpOnly flag is set. This means that only the server side code can modify this cookie.
请参阅: http://www.owasp.org/index.php/HTTPOnly
这篇关于使用Javascript删除会话cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!