node package manager


Espresso Transit

A utility library for messaging between iframes and their container.

Basic Use

In your container, broadcasting to an iframe:

transit.broadcast('EventName', messageObject, '.iframeSelector');

Listeing for events in an iframe:

transit.on('EventName', function (event, data) {
    console.log(data); //messageObject 

Broadcasting to the container from the iframe:

transit.broadcast('EventName', messageObject, window.parent);

Listening for iframe messages

transit.on('EventName', function (event, data) {
    console.log(data); //messageObject 

Transit Methods

  • transit.on(string eventName, function callback)
  • transit.broadcast(string eventName, object message, [object windowObject || string iframeSelector])
  • params, [object windowObject || string iframeSelector])
    • params object
    broadcast: eventName,
    data: {}, //broadcast object
    onReply: function (event, data) {
        console.log(data); //<-- transit.reply data
  • transit.reply(eventName, callback, [windowObject || iframeSelector])