问题
I am using the following code. According to this code, new window will open with the source of url given. But when printing, it is showing about:blank is printing. The page loads correctly. Before loading, the page url is also about:blank. But it changes to the given url soon.
var url="http://localhost:8080/hiring/docs/Keneth%20_1340800082258/Keneth%20_resume_1340800082258.pdf";
var printwindow = window.open(url, '_blank', 'fullScreen=yes');
//setTimeout('2000');
printwindow.focus();
printwindow.print();
回答1:
Have you tried:
printwindow.onload = function() {
printwindow.focus();
printwindow.print();
};
回答2:
I guess window.print()
runs before the page is actually loaded, because it takes microseconds to execute next command of your code, but the page won't load in microseconds, that's why it prints blank page, try print it after document load event.
FIX
I have noticed that you tries to print a PDF just now, I don't think that it is possible to print the PDF file just because you can see it in the browser. It's just an Adobe Reader plugin, because of the same reason you can't print the flash movies on the page
来源:https://stackoverflow.com/questions/11447382/window-print-does-not-take-the-current-url