First, putting the javascript at the end of the body
<script>
...
</script>
</body>
is trivial, if it happens to work.
Second, it isn't obvious why placing the script(s) 'statically' is not the complete solution (especially given that it works).
Finally, if for some reason you cannot give up on the event approach, Googling fordocument.addEventListener("DOMContentLoaded"
will return links to the three 'experts' in this field (plus [indirectly] a link to a working example at
http://javascript.nwbox.com/ContentLoaded/
which goes far beyond the others in detail).
Note, however, that these pages were all written - literally - years ago and may thus have been overtaken by events - particularly the release of IE8.
FWIW, it appears to me that the most compact solution
(function (i) {
var u = navigator.userAgent;
var e = /*@cc_on!@*/false;
var st = setTimeout;
if (/webkit/i.test(u)) {
st(function () {
var dr = document.readyState;
if (dr == "loaded" || dr == "complete") {
i()
} else {
st(arguments.callee, 10);
}
}, 10);
}
else if ((/mozilla/i.test(u) && !/(compati)/.test(u)) || (/opera/i.test(u))) {
document.addEventListener("DOMContentLoaded", i, false);
} else if (e) {
(
function () {
var t = document.createElement('doc:rdy');
try {
t.doScroll('left');
i();
t = null;
} catch (e) {
st(arguments.callee, 0);
}
})();
} else {
window.onload = i;
}
})(init);
may actually be the best.