This is a test of a few different ways to add a load listener. It seems like most all of them should work, but in Mozilla it seems as though only two do:
<body onload="pass_test('body_onload')">
document.onload = function() { pass_test("document_onload"); }
this.onload = function() { pass_test("this_onload"); }
window.onload = function() { pass_test("window_onload"); }
addListener(this, "load", function() { pass_test("this_listener"); });
addListener(window, "load", function() { pass_test("window_listener"); });
addListener(document, "load", function() { pass_test("document_listener"); });
addListener(document, "DOMContentLoaded", function() { pass_test("dom_content_listener"); });
<script defer="defer">pass_test("defered_script");</script>
<script defer="defer" src="javascript:'pass_test(\'defered_inline\')'" />
The dom event spec says:
The load event occurs when the DOM implementation finishes loading all content within a document, all frames within a FRAMESET, or an OBJECT element.
Only IE supports the defer
attribute and only for external scripts.
There is a good discussion of running once the DOM is complete rather than waiting for all the images and whatnot on Dean Edwards' blog.