Skip to content

FunTechInc/handshake

Repository files navigation

Promise-based postMessage iframe communication library. 0 dependencies, Lightweight.

$ npm i @funtech-inc/handshake --D
// CDN
<script src="https://unpkg.com/@funtech-inc/handshake@latest">

Example

parent

new Handshake.Parent({
   container: "container",
   url: "http://example.com/child",
}).ready(({ on, emit, container, iframe }) => {
   console.log(container); // HTMLElement
   console.log(iframe); // HTMLIFrameElement
   emit("parentToChild", "hello child");
   on("childToParent", (data) => {
      console.log(data);
   }); // Log... "hello parent"
});

child

new Handshake.Child({ url: "http://example.com/" }).ready(({ on, emit }) => {
   emit("childToParent", "hello parent");
   on("parentToChild", (data) => {
      console.log(data);
   }); // Log... "hello child"
});

License

MIT

About

🤝 Shake hands with iframe

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published