0
votes

I've been working on some code in js/html and it works great. I'm now trying to package it into an add-on for Firefox, and having some issues getting the XUL document correct.

PLAIN OLD HTML/JS

In my html test file between the <head></head> I have:

<script type="text/javascript" src="js/MyCode.js"></script> 

At the end of the test file before the </body> I have:

<script type="text/javascript">MyCode.Static.Init();</script>

FIREFOX ADD-ON: OVERLAY.XUL

In an overlay.xul file in the extension package I have :

        <?xml version="1.0"?>
    <overlay id="mycode"
        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
        <script type="application/x-javascript" src="chrome://mycode/content/MyCode.js"></script>
        <script>
window.addEventListener("load", function () { gBrowser.addEventListener("load",MyCode.Static.Init,true); }, false);
        </script>
    </overlay>

This does not seem to enter the method, but then again I'm not even sure if I've got the listeners firing properly. Would this be the correct way to duplicate what I was doing in plain old html/js ?

4

4 Answers

1
votes

See: https://developer.mozilla.org/en/Code_snippets/Progress_Listeners for how to catch all page changes/loads/reloads

0
votes

Are you sure that gBrowser is ready? Just as a sanity check, change the script tag to

 alert(gBrowser); 

to make sure that gBrowser is ready.

0
votes

This is correct:

gBrowser.addEventListener("load",function () { MyCode.Static.Init(); }, false);

-1
votes

How about:

<script>
  window.addEventListener("load", function () { MyCode.Static.Init(); }, false);
</script>

?