在浏览器关闭之前存储数据的方法 [英] Method to store data until browser is closed

查看:63
本文介绍了在浏览器关闭之前存储数据的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何方法(使用 JavaScript)如何在浏览器关闭之前存储会话?我想使用会话 cookie - 当 expires 未设置时,cookie 应该在浏览器关闭时过期.但是对于任何实际目的,这都不可用,因为带有显示我上次的窗口和标签 选项的 Firefox 即使在浏览器关闭后也不会清除会话 cookie.

is there any method (using JavaScript) how to store session until browser is closed? I wanted to use session cookie - when expires is not set the cookie is supposed to expire when browser is closed. But for any practical purpose this is not usable because Firefox with Show my windows and tabs from last time option does not clear session cookies even after browser is closed.

我也不能使用 onunloadonbeforeunload 因为我需要记住数据直到浏览器关闭,即使用户重新加载或转到其他页面然后又回来.

I also cannot use onunload or onbeforeunload because I need to remember the data until the browser is closed even when users reloads or goes to some other page and then comes back.

推荐答案

您可能对 sessionStoragelocalStorage 鲜为人知的表亲.它应该完全符合您的需要——在会话中存储变量并在会话结束时清除它们.

You might be interested in sessionStorage, localStorage's little-known cousin. It should do exactly what you need--store variables in a session and clear them when the session is ended.

这篇关于在浏览器关闭之前存储数据的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆