Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including postis with all npm packages installed. Try it out:

var postis = require("postis")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

postis v3.0.0

Lightweight wrapper around the PostMessage API

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"}
  });
});

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free