We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
由于业务需要,通过 JS 为一个页面添加 cookie 时,特意没有设置 expires 和 max-age 属性,这样可以保证 cookie 只在当前会话期间(session)有效。用户一旦关闭浏览器,该 cookie 就会被清除,之后再打开浏览器并访问该页面的话,就没有这个 cookie 了。
可是在用 Chrome 测试的时候,发现彻底关闭 Chrome 之后再重新打开,该页面的 cookie 依然存在,测试了几次始终如此。
上网 Google 了一下,才发现这是浏览器的刻意设置。如果设置了浏览器在启动时,继续浏览上次打开的网页,则浏览器在每次关闭时,不会删除已打开网页中有效期为 session 的 cookie。
不要用 session cookie,用 sessionStorage 就行,经过实际测试,的确能够满足需求。
The text was updated successfully, but these errors were encountered:
No branches or pull requests
问题描述
由于业务需要,通过 JS 为一个页面添加 cookie 时,特意没有设置 expires 和 max-age 属性,这样可以保证 cookie 只在当前会话期间(session)有效。用户一旦关闭浏览器,该 cookie 就会被清除,之后再打开浏览器并访问该页面的话,就没有这个 cookie 了。
可是在用 Chrome 测试的时候,发现彻底关闭 Chrome 之后再重新打开,该页面的 cookie 依然存在,测试了几次始终如此。
上网 Google 了一下,才发现这是浏览器的刻意设置。如果设置了浏览器在启动时,继续浏览上次打开的网页,则浏览器在每次关闭时,不会删除已打开网页中有效期为 session 的 cookie。
解决方案
不要用 session cookie,用 sessionStorage 就行,经过实际测试,的确能够满足需求。
参考资料
The text was updated successfully, but these errors were encountered: