How do I print the indicated div (without manually disabling all other content on the page)?
I want to avoid a new preview dialog, so creating a new window with this
I tried many of the solutions provided.None of them worked perfectly. They either lose CSS or JavaScript bindings. I found a perfect and easy solution that neither losses CSS nor JavaScript bindings.
HTML:
This is a sample text for printing purpose.
Do not print.
Javascript:
function printFunc() {
var divToPrint = document.getElementById('printarea');
var htmlToPrint = '' +
'';
htmlToPrint += divToPrint.outerHTML;
newWin = window.open("");
newWin.document.write("Print Page
");
newWin.document.write(htmlToPrint);
newWin.print();
newWin.close();
}