View on GitHub

windtalk

Simplest way to communicate between windows or iframes πŸ—£πŸ’¨

windtalk banner

windtalk πŸ—£πŸ’¨

Micro lib (742 bytes gzipped) that provides a seamless way for two WINDows to TALK to each other.

Usage

Let’s consider a case where a parent window wants to interact with an object in an iframe.

In the iframe:

const color = {
  red: 0,
  green: 0,
  blue: 0,
  update: function () {
    // update the ui
  }
};
windtalk.expose(color);

In parent window:

const color = windtalk.link(iframe.contentWindow);
color.red = 200;
color.green = 150;
color.blue = 10;
color.update();

Expose Functions (not just objects)

Consider a case where one window wants to invoke a function in another window (or iframe) and get the result back.

Window1:

function doAdd(a, b) {
  return a + b;
}
windtalk.expose(doAdd);

Window2:

const doAdd = windtalk.link(win1);
let result = await doAdd(2, 3);
console.log(result); // 5

Install

Download the latest from dist folder

or from npm:

npm install --save windtalk

Full API

Windtalk API

Examples

Examples page

License

MIT License (c) Preet Shihn

You may also be interested in

Workly - A really simple way to move a function or class to a web worker. Or, expose a function or object in a web worker to the main thread.