views:

349

answers:

4

Hi all,

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"&gt;
        <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 ?

A: 

How about:

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

?

xqib-team
That doesn't work as expected, that listener only triggers when a new browser window is created, not a new page. Need to find out how to call the init after EVERY page is loaded in the browser.
citizencane
A: 

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.

KZ
A: 

This is correct:

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

mrivard
A: 

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

me