【问题标题】:Angular Communication between 2 window of same Component [closed]相同组件的2个窗口之间的角度通信[关闭]
【发布时间】:2020-01-30 11:09:35
【问题描述】:

我正在尝试实现两个窗口之间的通信。

我使用Window.open() 打开一个组件新2 窗口。

2 个窗口中的相同组件 2 个不同实例无法在这 2 个窗口之间进行通信的问题。

你能帮忙吗?

【问题讨论】:

标签: javascript angular window.open postmessage window.opener


【解决方案1】:

您可以尝试 BroadsastChannel API:https://developer.mozilla.org/en-US/docs/Web/API/Broadcast_Channel_API

这就是它所针对的场景。

这相当简单。取自文档:

// Connection to a broadcast channel
var bc = new BroadcastChannel('test_channel');

// Example of sending of a very simple message
bc.postMessage('This is a test message.');

// Example of a simple event handler that only
// logs the event to the console
bc.onmessage = function (ev) { console.log(ev); }

// Disconnect the channel
bc.close()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-11
    • 1970-01-01
    • 2016-12-29
    • 1970-01-01
    • 1970-01-01
    • 2018-12-01
    • 2017-03-08
    相关资源
    最近更新 更多