title: How to fire "onload" event on document in IE
body: <p>I am currently developing Unit Tests for a Javascript method that detects the readiness of the document. This code is already at framework level, so please avoid mentions of this being already implemented in jQuery or another library.</p>
  
  <p>I have successfully simulated the 'readystatechange' change event with the following code:</p>
  
  <pre><code>var event;
  event = document.createEventObject();
  event.type = 'readystatechange';
  document.fireEvent('onreadystatechange',event);
  </code></pre>
  
  <p>I failed to do the same for the 'load' event. The following code results in an invalid argument error in IE7, thrown by the call to fireEvent on the last line:</p>
  
  <pre><code>event = document.createEventObject();
  event.type = 'load';
  document.fireEvent('onload',event);
  </code></pre>
  
  <p>Has anyone done this, or failed to do this before? I am also interested in any suggestion to fire the event in a different way.</p>
  
  <p><strong>Edit:</strong> following the suggestion by Crescent Fresh, I changed my code to:</p>
  
  <pre><code>event = document.createEventObject();
  event.type = 'load';
  document.body.fireEvent('onload',event);
  </code></pre>
  
  <p>There is no more error, but the listener for 'onload' does not fire. Here is how I configured it:</p>
  
  <pre><code>document.attachEvent('onload',listener);
  </code></pre>