admin管理员组文章数量:1391850
I am trying to set a delay between the time the pdf is opened and the print function is called on the pdf file. Currently nothing happens but if I move the print function outside of the setTimeout it will call the print function but this is not what I want because it is too quick and pdf has not been loaded. When I place alerts inside the setTimeout they are called fine with the specified 3 seconds.
var pdfWin = window.open(docPath);
setTimeout(function() {
pdfWin.print();
},3000)
My question is: why is the print function not being called?
Thanks in advance
I am trying to set a delay between the time the pdf is opened and the print function is called on the pdf file. Currently nothing happens but if I move the print function outside of the setTimeout it will call the print function but this is not what I want because it is too quick and pdf has not been loaded. When I place alerts inside the setTimeout they are called fine with the specified 3 seconds.
var pdfWin = window.open(docPath);
setTimeout(function() {
pdfWin.print();
},3000)
My question is: why is the print function not being called?
Thanks in advance
Share Improve this question asked Nov 20, 2012 at 0:09 sam.tldrsam.tldr 653 silver badges9 bronze badges 2- 4 You shouldn't use timeouts for that purpose. You can't possibly predict the time it will take for a file to be downloaded because the internet speed of the users and the server's response time will vary. You should use an event handler that fires when the file is downloaded. – JCOC611 Commented Nov 20, 2012 at 0:11
- I understand this and it is not the final solution. I just want to see the output before I move on to something else – sam.tldr Commented Nov 20, 2012 at 0:13
1 Answer
Reset to default 6var pdfWin = window.open(docPath);
pdfWin.onload = function() {
pdfWin.print();
};
Works fine for me in chrome.
Due to same-origin policy, you can only call .print()
on the window if it resides on the same domain as the parent window. Otherwise I could just open up your facebook on my page and submit some forms there ;p
本文标签: Javascript print using setTimeoutStack Overflow
版权声明:本文标题:Javascript print using setTimeout - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744770058a2624284.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论