My solution pilfered from somewhere but can't remember where:
//add the load eventListener to the window object
window.addEventListener("load", function() { functioname.init(); }, true);
var functionname = {
//add the listener for the document load event
init: function() {
var appcontent = document.getElementById("appcontent"); // browser
if(appcontent)
appcontent.addEventListener("DOMContentLoaded", functionname.onPageLoad, false);
},
//function called on document load
onPageLoad: function(aEvent) {
if(aEvent.originalTarget.nodeName == "#document"){
}
}
}