我尝试在JavaScript中打印PDF文件。我从服务器获取文件的URL。
var iframe = document.createElement('iframe');
document.body.appendChild(iframe);
iframe.style.display = 'none';
iframe.src = urlBaseImage + 'Report//' + result;
iframe.focus();
iframe.contentWindow.print();
但他给我的是空白页面,我检查了URL,它确实是正确的。我该怎么办?谢谢!
<iframe>
中?如果您只是将 PDF URL 输入浏览器地址栏,PDF 是否作为页面加载?如果前两个问题的答案都是否定的,那么您如何确认 URL 正确无误?顺便提一下,从 Chrome 46 开始,在<iframe>
中阻止window.print()
,除非它的sandbox
属性具有值allow-modal
。 - Nicholas