Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Postie.js & HTML postMessage API

Postie.js & HTML postMessage API

Paul Springett

June 13, 2013
Tweet

More Decks by Paul Springett

Other Decks in Technology

Transcript

  1. “window.postMessage is a method for safely enabling cross-origin communication.” —

    Mozilla Developer Network https://developer.mozilla.org/en-US/docs/Web/API/window.postMessage Thursday, 13 June 13
  2. Bookmarklets or 3rd party libs where cross-origin communication is required

    Popup windows (same-origin) Thursday, 13 June 13
  3. Can only send strings, no rich data No built in

    response or callback Thursday, 13 June 13
  4. Provides request / response format using callbacks Send rich data

    (JSON) Handles creating iframe, onload Thursday, 13 June 13
  5. var server = new Postie.Server({ getFoo: function(sendResponse) { sendResponse(“Here is

    your foo”); }, ... }); server.listen(); Setup the server Thursday, 13 June 13
  6. var server = new Postie.Server({ getUser: function(userID, sendResponse) { $.getJSON(“/users”,

    { id: userID }, function(data, status, xhr) { sendResponse(data); } ); } }); server.listen(); Setup the server Thursday, 13 June 13
  7. Postie.js is CoffeeScript CoffeeScript is awesome, go try it out

    http://coffeescript.org/ http://js2coffee.org/ http://coffeescript.codeschool.com/ Thursday, 13 June 13