views:

39

answers:

2

I get a notification when a html page is loaded

-> onStateChange, stateFlags: STATE_IS_NETWORK + STATE_STOP

but I need a notification when the page ist loaded and a onload script has finished running.

Any hints ? THX

A: 

Maybe you could add a second listener to "load" events. I was not able to find any documentation confirming that events listeners are called in order they are set, but some experiments with the code below shows that it seems to be the case. If there was a race condition I would expect to see sometimes "AB" and sometimes "BA":

<input type="text" id="field"/>

<script>

    var t = document.getElementById("field");
    t.value="";

    function a(e) {
        t.value = t.value + "A";
    }

    function b(e) {
        t.value = t.value + "B";
    }

    window.addEventListener("load", a, false);
    window.addEventListener("load", b, false);

</script>

One thing to be careful with this is that if you add the second event listener too late (i.e. the load event already fired) it will not be called.

Anyway, feels like a hack, but is just an idea in case you cannot find a better way to handle it.

fms
A: 

You could use:

gBrowser.addEventListener("DOMContentLoaded", function() { // Page content is loaded }, false);

but remember that gBrowser refers to the content of a tab so this will check every tab when it has been selected

Alex