0.1.1 • Published 8 years ago

iframe-postbox v0.1.1

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

iframe-postbox

A postmessage library inspire by Postmate

Use window.postMessage method to communication in iframe

Install

npm install

$ npm i --save iframe-postbox

browser import

<script src="node_modules/iframe-postbox/postbox.js></script>

Usage

parent.com

var handshake = new Postbox({
  container: document.getElementById('some-div'), // Element to inject iframe into
  url: 'http://child.com/page.html'
});

handshake.then(function(child) {
  child.get('name').then(function(value) {
    console.log(value)
  };

  child.on('some-event', function(data) {
    console.log(data)
  };
};

child.com/page.html

var handshake = new Postbox.Client({
  name: 'iframe child'
});

handshake.emit('some-event', 'Hello world')

API

See https://huang-x-h.github.io/iframe-postbox/api/index.html

Browser support

postbox.js support IE9+/Chrome/Safari/Firefox, need Promise polyfill

postbox.jquery.js supoort IE8+/Chrome/Safari/Firefox, base on jquery (use Deferred instead of 'Promise')