window-messenger
v1.0.3
Published
Sending messages between windows.
Downloads
4
Readme
window-messenger
window windowMessenger.open(string url[, any data])
Open a window with data:
a.html
windowMessenger.open('b.html', {
foo: 'some data',
bar: 'some data'
});
b.html
windowMessenger.getInitialData()
.then(console.log);
function windowMessenger.subscribe([string channelName,] function callback)
Subscribe a channel:
const unsubscribe = windowMessenger.subscribe('channel-name', (message) => {
console.log(message);
unsubscribe();
});
windowMessenger.send(window target, any data[, string channelName])
Send message to a channel:
windowMessenger.send(window.opener, {
foo: 'some data',
bar: 'some data'
}, 'my-channel');
const win = windowMessenger.open('b.html', {
foo: 'some data',
bar: 'some data'
});
windowMessenger.send(win, {
anotherFoo: 'new data',
anotherBar: 'new data'
});