I am using the following JavaScript code to print a <div>. I have called the printit() function on a button click. When the function runs, I am getting two windows. One is showing printing options, and in the background there is a preview window which is showing data from the <div> created by the function.
I want to exclude that background window. How can I do it?
<script>
function printit()
{
var DocumentContainer = document.getElementById('printthis');
var WindowObject = window.open('', 'PrintWindow', 'width=750,height=650,top=50,left=50,toolbars=no,scrollbars=yes,status=no,resizable=yes');
WindowObject.document.writeln(DocumentContainer.innerHTML);
WindowObject.document.close();
WindowObject.focus();
WindowObject.print();
WindowObject.close();
}
</script>
Instead of creating a window, which cannot be hidden, you can create a hidden iframe, write a document into it, and call the print function on its window object, if you want.