从一个应用程序关闭不同的浏览器选项卡

发布于 2025-02-13 08:03:33 字数 504 浏览 3 评论 0原文

我有2个应用程序,当我们单击App1中的链接时,可以访问App2。 每次单击此链接时,都会打开一个包含App2的新浏览器选项卡。

现在,我有一个要求,在注销App1时,应关闭针对App2打开的所有实例(TABS)。

我尝试捕获App2的窗口对象。并考虑使用winobj.close()用循环关闭其中的每个>。但是问题是如何以及在哪里可以捕获窗口对象? (当用户单击注销时,我需要获取这些对象)。

我尝试使用cookie和localstorage localstorage.setItem('app2window',json.stringify(window)) 但是JSON.STRINGIFY(窗口)给我以下错误:

uck typeerror:将圆形结构转换为JSON - >从构造函数“窗口”开始从对象开始 ---属性“窗口”关闭了圆圈 在json.stringify() 在:1:41

对此问题的任何帮助/指针都将不胜感激。

I have 2 applications where App2 is accessible when we click on a link in App1.
Each time this link is clicked, a new browser tab is opened containing App2.

Now I have a requirement where upon logout of App1, all the instances (tabs) opened for App2 should be closed.

I tried capturing window objects of App2. And thought of using winObj.close() to close each one of them with a loop. But the problem is that how and where can I capture window Objects ? (I need to get those objects when user clicks on logout).

I tried in cookie and localStorage by using
localStorage.setItem('app2Window', JSON.stringify(window))
but JSON.stringify(window) gives me following error:

Uncaught TypeError: Converting circular structure to JSON
--> starting at object with constructor 'Window'
--- property 'window' closes the circle
at JSON.stringify ()
at :1:41

Any help/pointers towards this problem will be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

铜锣湾横着走 2025-02-20 08:03:33

看起来您要寻找的是广播渠道:

Looks like the BroadcastChannel is what you're looking for:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文