Socket
Socket
Sign inDemoInstall

iframe-rpc-util

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    iframe-rpc-util

RPC between cross-origin iframe using postMessage


Version published
Maintainers
1
Created

Readme

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

FAQs

Last updated on 09 Sep 2023

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc