javascript 多选项卡 LocalStorage 单用户用例
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28812192/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Multiple Tab LocalStorage single user Use case
提问by chris
I currently have a SaaS B2B product, I'd love to show for the sake of example, if it weren't behind a VPN. But the case is, Its built on top of Zend Framework it is using Zend's session handling. That said my users recently decided that with recent improvements to various ends of the UI that they want to use the Service across multiple tabs at once, which isn't exactly currently supported, but in the name of wanting to keep on improving. I have to meet demands. That said. With this one piece of the service I have been managing data with cookies, since the page can be reloaded, and the UI re-rendered respectively to match the reloaded UI (the reload is triggered by content in an iFrame, since we can't communicate parent child from within the frame.
我目前有一个 SaaS B2B 产品,如果它不是在 VPN 后面,我很乐意展示作为示例。但情况是,它建立在 Zend 框架之上,它使用 Zend 的会话处理。也就是说,我的用户最近决定,随着最近对 UI 各个端的改进,他们希望一次跨多个选项卡使用该服务,目前尚不完全支持,但希望继续改进。我必须满足要求。那说。有了这一项服务,我一直在用 cookie 管理数据,因为可以重新加载页面,并且 UI 分别重新渲染以匹配重新加载的 UI(重新加载由 iFrame 中的内容触发,因为我们不能从框架内沟通父子。
However now that my users are insisting on doing the same action across multiple tabs trying to save time, this breaks the UI since the cookies are not in any way shape or form tagged with an ID, from which I wouldn't even know how to imply that since I can't necessarily track tabs. So With all this I figured i'd give localstorage a go. However I am still not sure how to handle a single user on multiple tabs to prevent UI data being used on different tabs, more so if the page gets refreshed at a given time which could maybe lose data in localstorage?
但是,现在我的用户坚持在多个选项卡上执行相同的操作以节省时间,这破坏了 UI,因为 cookie 没有以任何方式标记有 ID 的形状或形式,我什至不知道如何从中暗示,因为我不一定能跟踪标签。所以有了这一切,我想我会试一试localstorage。但是,我仍然不确定如何在多个选项卡上处理单个用户以防止在不同选项卡上使用 UI 数据,更何况如果页面在给定时间刷新,这可能会丢失本地存储中的数据?
So what I am trying to figure out all in all. Is how to manage this single user across one or more tabs without one tabs data interfering with the other tabs data, since the actions and ui are all contained within the same domain. (Does this clarify anything better?)
所以我想弄清楚所有的一切。是如何跨一个或多个选项卡管理这个单个用户,而一个选项卡数据不会干扰其他选项卡数据,因为操作和 ui 都包含在同一个域中。(这是否更能说明问题?)
回答by Ewald Stieger
Yes, you can use localStorage
to store data for your web app. Also, have a look at sessionStorage
which is window/tab specific and stores data per session.
是的,您可以使用它localStorage
来存储 Web 应用程序的数据。另外,看看sessionStorage
哪个是特定于窗口/选项卡的并存储每个会话的数据。
Read more here:
在此处阅读更多信息: