Package detail

postis

adtile27.2kMIT2.2.0

Lightweight wrapper around the PostMessage API

postmessage, iframe

readme

Postis

Postis is a light wrapper around the PostMessage API

Installation

$ npm install --save postis

Usage

Parent HTML which contains an iframe:

var postis = require("postis");
var targetWindow = document.querySelectorAll("iframe")[0].contentWindow;

var channel = postis({
  window: targetWindow,
  scope: "scope-for-message-changing-to-avoid-overlapping"
});

channel.ready(function() {
  channel.listen("remoteMessageFromChild", function(remoteMessage) {
    console.log("remoteMessageFromChild:", remoteMessage);
  });

  channel.send({
    method: "remoteMessageFromParent",
    params: { awesome: "messsage",
              from: "Parent window"}
  });
});

In embedded child iframe:

var postis = require("postis");
var targetWindow = window.parent;

var channel = postis({
  window: targetWindow,
  scope: "scope-for-message-changing-to-avoid-overlapping"
});

channel.ready(function() {
  channel.listen("remoteMessageFromParent", function(remoteMessage) {
    console.log("remoteMessageFromParent:", remoteMessage);
  });

  channel.send({
    method: "remoteMessageFromChild",
    params: { awesome: "messsage",
              from: "child iframe"}
  });
});

Release

New releases are prepared in master after merging the PRs. Please include a meaningful changelog entry in PR.

Write a new CHANGELOG.md entry before running built-in npm version bump and add the change to next commit.

npm version <major | minor | patch>
git push --tags

npm version should include added changelog entry in the commit. Remember to push changes.

changelog

Change Log

All notable changes to this project will be documented in this file. This project adheres to Semantic Versioning.

[2.2.0] - 2016-02-01

Added

  • Adds destroy method to Postis channel

[2.1.1] - 2016-01-28

Fixed

  • Check that targetWindow has postMessage property on send

[2.1.0] - 2016-01-20

Added

  • Support for windowForEventListening which can be used with sourceless iframes.

[2.0.1] - 2016-01-20

Fixed

  • Add try catch block around JSON.parse to handle non JSON payloads.

[2.0.0] - 2015-11-18

Changed

  • params are now passed as-is, not converted into function arguments.

[1.1.0] - 2015-10-20

Added

  • Initial Open Source release.