简体   繁体   English

Angular 8 防止在复制选项卡上的浏览器选项卡之间共享会话

[英]Angular 8 prevent sharing session between browser tabs on duplicating tabs

I read blogs on session storage and local storage.我阅读了有关会话存储和本地存储的博客。 Now as per my understanding现在按照我的理解

Session Storage : The session Storage exists only within the current browser tab.会话存储:会话存储仅存在于当前浏览器选项卡中。 Another tab with the same page will have a different session storage.具有相同页面的另一个选项卡将具有不同的会话存储。

Local Storage : Data is shared between all tabs and windows from the same origin.本地存储:数据在来自同一来源的所有选项卡和窗口之间共享。

Now my requirement is whenever user opens a new tab or duplicate a previously opened tab in same window I can see session storage have some value.现在我的要求是,每当用户打开一个新选项卡或在同一窗口中复制以前打开的选项卡时,我都可以看到会话存储具有一定的价值。 If user open a new tab or duplicate the currently opened tab I want my session storage to be empty and generate a new session key .But if user refresh or reload page I want to continue with same session Storage.如果用户打开一个新选项卡或复制当前打开的选项卡,我希望我的会话存储为空并生成一个新的会话密钥。但是如果用户刷新或重新加载页面,我想继续使用相同的会话存储。

Note : I am not sharing session in my code, neither I am storing anything from local storage to session storage.注意:我没有在我的代码中共享会话,也没有存储从本地存储到会话存储的任何内容。 Any idea how can I achieve above scenario.任何想法我怎样才能实现上述场景。

You can generate a hash when your application load and save keys with this hash in your localStorage ?您可以在您的应用程序加载时生成一个散列并将该散列保存在您的 localStorage 中吗?

The app.component.ts construct() will fire only when you load for the first time. app.component.ts construct()只会在您第一次加载时触发。 You can get the browser tabId with window.tabId您可以使用window.tabId获取浏览器window.tabId

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM