Can a web app in xul:iframe access functions from its parent XUL file?

Posted by oskar on Stack Overflow See other posts from Stack Overflow or by oskar
Published on 2010-06-16T02:06:47Z Indexed on 2010/06/16 2:12 UTC
Read the original article Hit count: 346

Filed under:
|
|
|
|

I want to deploy a web app as a self-contained program using XULRunner. I'm simply loading it in a xul:iframe tag within the main XUL file. It works, but I want the web app to have access to XUL components, specifically nsiFilePicker.

My tentative solution is to run the xul:iframe with escalated privileges (by omitting the "type" attribute), wait for the xul:iframe to load, then define a javascript function that the web app will then call.

<window id="main" width="800" height="600" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  <iframe id="contentview" src="web/index.html" flex="1"/>
  <script>
    //listen for XUL window to load
    window.addEventListener("load",Listen,false);
    function Listen()
    {
      var frame = document.getElementById("contentview");
      frame.addEventListener("DOMContentLoaded", DomLoadedEventHandler, true);
    }

    //listen for iframe to load
    function DomLoadedEventHandler() {
      //set function in iframe called testMe()
      var frame = document.getElementById("contentview");
      frame.contentWindow.testMe = function () {
        alert("This is a test");
      };
    }
  </script>
</window>

...and then in the index.html file of the web app...

<script>
  testMe();
</script>

This doesn't seem to work. Does anyone have any suggestions?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about firefox