https://github.com/cristiantela/iframessa
Communicate between iframes and application
https://github.com/cristiantela/iframessa
communication-with-iframe iframes micro-frontend postmessage
Last synced: 5 months ago
JSON representation
Communicate between iframes and application
- Host: GitHub
- URL: https://github.com/cristiantela/iframessa
- Owner: cristiantela
- Created: 2021-10-28T03:20:47.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-03-23T03:12:02.000Z (over 3 years ago)
- Last Synced: 2025-09-30T02:18:15.743Z (9 months ago)
- Topics: communication-with-iframe, iframes, micro-frontend, postmessage
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/iframessa
- Size: 14.6 KB
- Stars: 15
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# iframessa
Package to communicate between iframes and application.
## Install
```
npm install iframessa
```
## Usage examples
### Case 1: You would like to receive the logged user name from your web application into your iframe.
#### 1. Create a getter on your parent window
```html
```
```javascript
const iframessa = require('iframessa');
iframessa.getter('userName', ({ data, sender }) => {
return 'Matheus Cristian';
});
```
#### 2. Call the getter on your child window
```javascript
const iframessa = require('iframessa');
iframessa.register('about');
iframessa.get('userName').then(({ data, sender }) => {
console.log(data); // Matheus Cristian
console.log(sender); // parent object
}, data);
```
### Case 2: You would like to emit an event with a data from your child window to your parent
#### 1. Emit a message to your parent window from your iframe
```javascript
const iframessa = require('iframessa');
iframessa.emit('action', 'logout');
```
This will emit a `'action'` event to your parent with the data `'logout'`.
Note that the data can be an object as well.
#### 2. Make your parent watch the `'action'` event
```javascript
const iframessa = require('iframessa');
iframessa.on('action', ({ data, sender }) => {
console.log(data); // logout
});
```
You can emit something to a specific child window with `iframessa.modules.about.emit(event, data);`