A postmessage library inspire by Postmate
Use window.postMessage
method to communication in iframe
npm install
$ npm i --save iframe-postbox
browser import
<script src="node_modules/iframe-postbox/postbox.js></script>
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) {
alert(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')
See https://huang-x-h.github.io/iframe-postbox/api/index.html
postbox.js
support IE9+/Chrome/Safari/Firefox
, Promise
polyfill
postbox.jquery.js
supoort IE8+/Chrome/Safari/Firefox
, base on jquery
(use Deferred
instead of 'Promise')