postmessage-client-server
A simple promise-based client and server to communicate between pages and iframes with postmessage.
All data passed will be serialized with JSON.
Installation
In your project dir:
npm install --save postmessage-client-server
Server
In your page the iframe will load on your server:
; ;
Client
On your client webpage:
; const urlToServerPage = 'http://mycorp.com/serverFrame.html'; // adds an iframe to the given url in your page ;
Output
The console output from the above example would be:
SERVER: Sniffing...CLIENT: We smelt: "grass" "ball"SERVER: Bark at grassSERVER: Bark at ballSERVER: About to misbehave...CLIENT: Got punished for Eating shoeCLIENT: Bark result: Barked at grassCLIENT: Bark result: Barked at ball
Remember that the calls are asynchronous, so the order may vary.
Module submitted by Erik Rasmussen @erikras