title: Javascript document.open asynchronous?
body: <p>So on my site there is a Javascript function that will load a new site from the server via XMLHttpRequest. After that it replaces the current page with the new one:</p>
  
  <pre><code>var post = new XMLHttpRequest();
  post.open('POST', data);
  post.onload = function() {
      var do = document.open("text/html", "replace");
      do.write(post.responseText);
      do.close();
      goOn();
  }
  
  function goOn() {
      console.log($('img:visible'));
  }
  </code></pre>
  
  <p>Some could assume that after do.close() the document has changed and is ready. But it is not, e.g. if i load very much/big data/responseText the function goOn() only logs an empty result. Obviously goOn() gets in that case called before the DOM is ready to be read!
  Unfortunately the is no "ready" event fired after write() finished....
  How can i be sure it is finished?  </p>
  
  <p>/EDIT:
  goOn() logs this to Chrome Console:</p>
  
  <pre><code>[prevObject: p.fn.p.init[1], context: #document, selector: "img:visible"]
  context: #document
  length: 0
  prevObject: p.fn.p.init[1]
  selector: "img:visible"
  __proto__: Object[0]
  </code></pre>
  
  <p>But if i right after that type $('img:visible') into console manually it shows me all images....</p>