Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Communicate between iframes and application

NotificationsYou must be signed in to change notification settings

cristiantela/iframessa

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

<iframesrc="about.html"name="about"></iframe>
constiframessa=require('iframessa');iframessa.getter('userName',({ data, sender})=>{return'Matheus Cristian';});

2. Call the getter on your child window

constiframessa=require('iframessa');iframessa.register('about');iframessa.get('userName').then(({ data, sender})=>{console.log(data);// Matheus Cristianconsole.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

constiframessa=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

constiframessa=require('iframessa');iframessa.on('action',({ data, sender})=>{console.log(data);// logout});

You can emit something to a specific child window withiframessa.modules.about.emit(event, data);


[8]ページ先頭

©2009-2025 Movatter.jp