cross-page-communication
TypeScript icon, indicating that this package has built-in type declarations

3.8.0 • Public • Published

how to use

最典型的用法是构建跨页面的页面级 api 服务。

如一个web应用内,包含一个iframe, iframe中的页面需要调用父页面中的某个方法。

那么父页面则是接口提供方,iframe页面事接口调用方。

code demo

npm i cross-page-communication --save

对于接口提供方:

import { Server } from 'cross-page-communication'

var server = new Server('@serverName');
server.start();

server.onMessage(function(event) {
    var msg = event.data;

    switch (msg.title) {
        case 'hi':
            //do something
            break;
    }
});

对于接口调用方:

import { Client } from 'cross-page-communication'

var client = new Client();
client.start();

client.postMessage({
    from 'clientName',
    to: '@serverName',
    title: 'hi',
    body: "dad. I love you!"
});

Readme

Keywords

none

Package Sidebar

Install

npm i cross-page-communication

Weekly Downloads

8

Version

3.8.0

License

MIT

Unpacked Size

88 kB

Total Files

39

Last publish

Collaborators

  • kevinwon