DomContentLoaded fires repeatedly
Hello --
I'm working on a Firefox extension that will manipulate pages when
they are loaded. I'm watching for the DOMContentLoaded event, but it
seems to fire repeatedly. When I am not connected to the internet,
Firsfox displays the standard "Server not found" message with a single
"HELLO WORLD" inserted at the end, as should happen. However, when I
am connected to the internet, the browswr freezs on page load, and,
after a time, unfreezes and has thousands of "HELLO WORLD"s at the
bottom of the page. The only explanation I can think of is that
DOMContentLoaded is fired many times.
I'm using Firefox 3.5.2 on Ubuntu x86_64.
Here's the javascript that's loaded from my overlay:
++++++++++++++++++++++++++++++++++++
var helloworld = {
onLoad: function() {
this.initialized = true;
this.strings = document.getElementById("helloworld-strings");
this.appcontent = document.getElementById("appcontent");
this.appcontent.addEventListener("DOMContentLoaded",
helloworld.onPageLoad, false);
},
onPageLoad: function(e) {
content.document.documentElement.innerHTML += '<p>HELLO WORLD!!!!!</
p>';
}
};
window.addEventListener("load", function(e) { helloworld.onLoad(e); },
false);
++++++++++++++++++++++++++++++++++++
and the overlay:
+++++++++++++++++++++++++++++++++++++
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="chrome://helloworld/skin/overlay.css"
type="text/css"?>
<!DOCTYPE overlay SYSTEM "chrome://helloworld/locale/helloworld.dtd">
<overlay id="helloworld-overlay"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/
there.is.only.xul">
<script src="overlay.js"/>
<stringbundleset id="stringbundleset">
<stringbundle id="helloworld-strings" src="chrome://helloworld/
locale/helloworld.properties"/>
</stringbundleset>
</overlay>
+++++++++++++++++++++++++++++++++++++
and chrome.manifest:
++++++++++++++++++++++++++++++++++++++
content helloworld content/
locale helloworld en-US locale/en-US/
skin helloworld classic/1.0 skin/
overlay chrome://browser/content/browser.xul chrome://helloworld/content/firefoxOverlay.xul
style chrome://global/content/customizeToolbar.xul chrome://helloworld/skin/overlay.css
++++++++++++++++++++++++++++++++++++++
Any solutions, advice, or pointers to helpful articles/documentation
would be much appreciated.
Re: DomContentLoaded fires repeatedly
Why do you add another event listener to a previous declared one? of
course that will iterate continuously while all resources are loaded.
Why not set the DOMContentLoaded event listener directly on the
window? or maybe I don't understand what you are trying to achieve
here, it seems a race condition you created.
Re: DomContentLoaded fires repeatedly
On Sep 24, 9:47*am, 0x000000 <jungs...@gmail.com> wrote:[color=blue]
> Why do you add another event listener to a previous declared one? of
> course that will iterate continuously while all resources are loaded.
> Why not set the DOMContentLoaded event listener directly on the
> window? or maybe I don't understand what you are trying to achieve
> here, it seems a race condition you created.[/color]
The symptoms (repeated execution of onPageLoad) persist when I change
the code to attach the DOMContentLoaded event to the window:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
var helloworld = {
onLoad: function() {
this.initialized = true;
this.strings = document.getElementById("helloworld-strings");
this.appcontent = document.getElementById("appcontent");
},
onPageLoad: function(e) {
content.document.documentElement.innerHTML += '<p>HELLO WORLD!!!!!
</p>';
}
};
window.addEventListener("load", function(e) { helloworld.onLoad(e); },
false);
window.addEventListener("DOMContentLoaded", function(e)
{ helloworld.onPageLoad(e) }, false);
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Thanks,
Ben