iframe-rpc-util
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'
const iframeProxy = iframeRpc('iframeNode')
iframeProxy.parentFunc = (data) => {
return 'parent function'
}
window.onload = () => {
iframeProxy.childrenFunc('parent params').then((data) => {
console.log('parent', data)
})
}
children Iframe
import iframeRpc from 'iframe-rpc-util'
const iframeProxy = iframeRpc()
iframeProxy.childrenFunc = (data) => {
return 'children function'
}
iframeProxy.parentFunc('children params').then((data) => {
console.log('children', data)
})
If you like it, please star it