Instead of adding a new window, you can add a special print area to your web page, which is only visible when printing. A.
http://jsfiddle.net/cp3zS/
HTML
<div class="non-printable"> Foo </div> <div class="printable"> </div>
CSS
@media screen { .printable { display: none;} .non-printable { display: block;} } @media print { .non-printable { display: none;} .printable { display: block;} }
Js
var h = "<html><head></head><body><h1>Example</h1><p>This is a variable I want to print to the printer with the browser!</p></body></html>" $('.printable').html(h); window.print();
source share