Window.print() does not take the current url

纵饮孤独 提交于 2019-12-24 19:46:56

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!