2

有没有办法以与 sessionStorage 相同的方式在 indexedDB 上存储临时数据:同一域的其他会话(选项卡)不可用,并在会话关闭时过期(影响 storeObject 或整个 storeObject 上的某些项目)?

我可以创建一个具有随机名称的 storeObject 并添加 unload 事件侦听器以在用户退出页面时删除此 storeObject。但这里的问题是,即使用户只是从一个页面更改为同一域上的另一个页面或刷新页面,storeObject 也会被删除,...(相同的会话)。

我知道有一些基于 document.cookie API 的类似 sessionStorage 的存储的实现,这对我的情况来说并不是一个完美的解决方案。

4

1 回答 1

2

I'm not sure if there is a way to do what you want to do. I believe that indexDB is persistent until deleted. You could delete based on a timestamp, this can only happen after the user returns, or logoff button.

This may help you may be able to user localStorage if your not storing to much data: http://www.sitepoint.com/an-overview-of-the-web-storage-api/

If you are worried about concurrent data overrides you can implement locks: http://balpha.de/2012/03/javascript-concurrency-and-locking-the-html5-localstorage/#comments

于 2014-01-19T22:21:06.963 回答