title: How does the Javascript print function work? Can I create a document using javascript and print it off?
body: <p>I know you can use window.print() to print the current page... but what I want to know is can I build a document using javascript in order to populate it with data and print it off?</p>
  
  <p>Just like you can have html/xml as a javascript object, can you do something similar to this:</p>
  
  <pre><code>var name = "Matt";
  var htmlDocumentToPrint = "&lt;html&gt;&lt;body&gt;&lt;div style='width:300px; height:20px; background-color:#000; text-align:center;'&gt;My name is " + name + "&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;";
  
  htmlDocumentToPrint.print();
  </code></pre>
  
  <p>I don't really care about adding colors all that much-- just want to format a document, populate it with data, and print it off. Is this possible?</p>