title: window.print is not working for a page that has been rendered by document.write
body: <p><strong>Scenario:</strong> 
  I'm creating a new window (new tab) and writing html markup to it via javascript.
  1. new document.
  2. write html markup to document's content.
  3. show the new document.</p>
  
  <p><strong>What I need to do:</strong>
  I basically need to print a simple HTML page (javascript print dialog) by clicking on a button, link, or onload.
  The problem, is i cant get either way to work... with one exception.</p>
  
  <p>(the one exception) Using the onload="window.print()" will only work if the new window appears and i click refresh (the print dialog wont display upon initial creation of the window).</p>
  
  <p>The weird thing is, even if i invoke "window.print()" on event clicks (href, button...etc) nothing happens. But I know it's not the browser because samples/demos of this SIMPLE thing works just fine.</p>
  
  <p>So it seems it's somehow related to my page being rendered the way it is (described in the "Scenario" section of this).</p>
  
  <p><strong>CODE:</strong>
  When i click on a Print button, i call this (right now it is not important exactly who/what calls this. but just know that it is called):</p>
  
  <pre><code>function Print(htmlContent) {
    var printWindow = window.open();
    var printDoc = printWindow.document;
    printDoc.write(htmlContent);
  </code></pre>
  
  <p>And i forgot to mention this: The HTML (htmlContent) that is passed to the Print scrip function is indeed Html, but it has been transformed by an XSL. Here is the XSL:</p>
  
  <pre><code>&lt;?xml version="1.0" ?&gt;
  &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
    &lt;xsl:template match="/"&gt;
      &lt;html&gt;
      &lt;head&gt;
          &lt;style type="text/css" media="print"&gt;
              .noprint{
                      display:none;
                  }
          &lt;/style&gt;
          &lt;script type='text/javascript'&gt;
              function startPrint(){
                  window.print();
              }
          &lt;/script&gt;
      &lt;/head&gt;
  
        &lt;body&gt;        
          &lt;div &gt;
              &lt;a id="printButton" href="startPrint();"&gt;Print this page&lt;/a&gt;
          &lt;/div&gt;
          Hello world.
  &lt;/body&gt;
      &lt;/html&gt;
    &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>I can confirm javascript works because if i replace the href="startPrint()" with href="alert('hi')", i do indeed get a popup with that alert.</p>