title: Getting notified when the page DOM has loaded (but before window.onload)
body: <p>I know there are some ways to get notified when the page body has loaded (before all the images and 3rd party resources load which fires the <strong>window.onload</strong> event), but it's different for every browser.</p>
  
  <p>Is there a definitive way to do this on all the browsers?</p>
  
  <p>So far I know of:</p>
  
  <ul>
  <li><p><strong>DOMContentLoaded</strong> : On Mozilla, Opera 9 and newest WebKits. This involves adding a listener to the event:</p>
  
  <p>document.addEventListener( "DOMContentLoaded", [init function], false );</p></li>
  <li><p><strong>Deferred script</strong>: On IE, you can emit a SCRIPT tag with a @defer attribute, which will reliably only load after the closing of the BODY tag.</p></li>
  <li><p><strong>Polling</strong>: On other browsers, you can keep polling, but is there even a standard thing to poll for, or do you need to do different things on each browser?</p></li>
  </ul>
  
  <p>I'd like to be able to go without using document.write or external files.</p>
  
  <p>This can be done simply via jQuery:</p>
  
  <pre><code>$(document).ready(function() { ... })
  </code></pre>
  
  <p>but, I'm writing a JS library and can't count on jQuery always being there.</p>