Frage

I'm creating a widget for Firefox OS's homescreen. I've separated the widget as another application in B2G, and in homescreen, I load the widget's content in an iframe. Since it's from a different domain, I modify the domain so they're equal, but when I register the event handler, it still doesn't work:

(widget is the iframe object, foo is my function.) widget.contentWindow.oncontextmenu = foo;

My handler is still not called in response to the 'contextmenu' event.

However, when I put the widget module in the homescreen module and let them be one web app, it works normally.

War es hilfreich?

Lösung

contentWindow is not accessible cross-origin. A different app has a different origin.

If you added a mozbrowser iframe to the homescreen app, you could load your widget from a URL in that iframe and listen for the mozbrowsercontextmenu event on the iframe.

<iframe id="widget" mozbrowser=true></iframe>

var widget = document.getElementById('widget');
widget.addEventListener('mozbrowsercontextmenu', eventHandler);

See the browser app for an example of how to handle the contextmenu event https://github.com/mozilla-b2g/gaia/blob/master/apps/browser/js/browser.js#L1021

This would require adding the "browser" permission to homescreen app.

If you wanted to load it as an app then you'd need the mozapp attribute on the iframe too and would need to point to the manifest of the app. This is how the window manager in the system app embeds apps in an iframe.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top