You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

iframe-rpc-util

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

iframe-rpc-util

RPC between cross-origin iframe using postMessage

1.0.4
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

iframe-rpc-util

npm

RPC between cross-origin iframe using postMessage

Installation

$ npm install iframe-rpc-util

$ yarn add iframe-rpc-util

$ pnpm install iframe-rpc-util

Usage

Parent Iframe

<iframe src="xx" id="iframeNode"></iframe>
import iframeRpc from 'iframe-rpc-util'

// init rpc instance
const iframeProxy = iframeRpc('iframeNode')

// iframe init event
iframeProxy.onReady = (data) => {
    // get rpc register function
    iframeProxy.getKeys().then((data) => {
        console.log('parent getKeys', data)
    })

    // call children function
    iframeProxy.childrenFunc('parent params').then((data) => {
        console.log('parent', data)
    })
}

// register function
iframeProxy.parentFunc = (data) => {
    // return remote data
    return 'parent function'
}

Children Iframe

import iframeRpc from 'iframe-rpc-util'

const iframeProxy = iframeRpc()

// register function
iframeProxy.childrenFunc = (data) => {
    // return remote data
    return 'children function'
}

iframeProxy.parentFunc('children params').then((data) => {
    console.log('children', data)
})

If you like it, please star it

Keywords

iframe

FAQs

Package last updated on 09 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts