Question

Is it possible to communicate between two packaged apps in Firefox OS using postMessage, like the way when you post a messages from a parent to an Iframe:

var targetOrigin = document.location.protocol + '//' + document.location.host;
var otherWindow = document.getElementById("iframe").contentWindow;
otherWindow.postMessage("TestMessage", targetOrigin);

So my questions are:

  1. How do I get hold of the reference to the window object of the other app(otherWindow above) or is it possible to do a postMessage in another way to reach the other app?
  2. How do I specify the targetOrigin, app://xxxx?
Était-ce utile?

La solution

The same origin policy (http://en.wikipedia.org/wiki/Same-origin_policy) prevents you from getting a reference to the window object and using postMessage to an app from a different origin. Each packaged app has its own origin.

There is a new API being developed to do what you're talking about in a safe way called the Inter-app Communications API (https://wiki.mozilla.org/WebAPI/Inter_App_Communication_Alt_proposal), but I think that is only currently only available for certified apps until it is a bit more stable.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top