Reputation: 563
I am quite new to javascript. I want to load a html page into new window and print that page. The page is successfully loaded. But it only prints a blank page. (Test with MS XPS document writer) Here is my code..
var newWin=window.open("Home.html","_blank","menubar=0,resizable=1,width=320,height=320");
newWin.focus();
newWin.print();
newWin.close();
Upvotes: 0
Views: 2497
Reputation: 171679
Use a load handler on the new window so print won;t start until page is loaded
newWin.onload=function(){
newWin.focus();
newWin.print();
newWin.close();
}
Upvotes: 2
Reputation: 8589
Try this: The content that you're trying to print might not have loaded fully yet when the print command is issued, so by wrapping it in a timer, you force the print to be placed at the end of the execution queue.
var newWin = window.open("Home.html","_blank","menubar=0,resizable=1,width=320,height=320");
setTimeout(function() {
newWin.focus();
newWin.print();
newWin.close();
}, 1);
Upvotes: 1