如何删除会话 Cookie? [英] How to Delete Session Cookie?
问题描述
如何在不手动重启浏览器的情况下,通过javascript动态删除会话cookie?
How to dynamically, via javascript, delete a session cookie, without manually restarting the browser?
我在某处读到会话 cookie 保留在浏览器内存中,并且会在浏览器关闭时被删除.
I read somewhere that session cookie is retained in browser memory and will be removed when the browser is closed.
// sessionFooCookie is session cookie
// this code does not delete the cookie while the browser is still on
jQuery.cookie('sessionFooCookie', null);
谢谢.
更多信息:上面的代码片段是一个javascript 代码片段,使用 jQuery以及它的 jQuery.cookie 插件.
More Info: The code snippet above is a javascript code snippet, using jQuery and its jQuery.cookie plugin.
推荐答案
会话 cookie 只是一个没有到期日期的普通 cookie.这些由浏览器处理,直到窗口关闭或程序退出才有效.
A session cookie is just a normal cookie without an expiration date. Those are handled by the browser to be valid until the window is closed or program is quit.
但如果 cookie 是 httpOnly
cookie(带有 httpOnly
参数 设置),您不能从 HTTP 外部读取、更改或删除它(意味着它必须在服务器上更改).
But if the cookie is a httpOnly
cookie (a cookie with the httpOnly
parameter set), you cannot read, change or delete it from outside of HTTP (meaning it must be changed on the server).
这篇关于如何删除会话 Cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!