简体   繁体   中英

Firefox OS Inter App Communication with postMessage

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM