js action communicator between parent window and iframe
npm install iframe-action-communicatorIt's module for communicate parent with iframe and vice versa. So, it's very easy way to start events on the opposite side.
The only thing that will be necessary it's object or string with name of action and data (if you want)
one side
---
``js`
iac.send({
action: 'somePowerfullAction',
data: 'somedata'
});
or
`js`
iac.send('somePowerfullAction'); // only for start action without data
opposite side
---
`js`
iac.on('somePowerfullAction', (data) => {
console.log(data);
});
That's all! It's so easy, isn't it?
Below you will be able to see more details and surely look at an Demo.
bash
$ npm install iframe-action-communicator
`
or
`html
`
$3
$3
`javascript
const parent = new IframeActionCommunicator('iframe'); // set 'id' of iframe// send message to iframe with name of action
parent.send({
action: 'messageFromParent',
data: 'Hello, I\'m Parent'
});
// describe on action 'messageFromIframe' from iframe
parent.on('messageFromIframe', function(data) {
console.log('messageFromIframe:', data);
// do something...
})
`$3
`javascript
const iframe = new IframeActionCommunicator();// send message to parent with name of action
iframe.send({
action: 'messageFromIframe',
data: 'Hello, I\'m Iframe'
});
// describe on action 'messageFromParent' from parent
iframe.on('messageFromParent', function(data) {
console.log('messageFromIframe:', data);
// do something...
})
``MIT