简体   繁体   English

防止嵌入PDF <object> 从打开打印对话框

[英]Prevent embedded PDF <object> from opening print dialog

In my application I'm embedding PDFs from unknown sources in an HTML object tag. 在我的应用程序中,我将来自未知来源的PDF嵌入HTML对象标签中。 This works great in most cases, but sometimes a PDF will have embedded javascript instructing the PDF to print when it opens. 在大多数情况下,此方法效果很好,但有时PDF会嵌入嵌入式javascript,以指示PDF在打开时进行打印。 When these PDFs load they open the print dialog, which is a very frustrating user experience. 加载这些PDF时,它们会打开“打印”对话框,这是非常令人沮丧的用户体验。

This is what my PDF object looks like. 这就是我的PDF对象的样子。

<object id="foo" data="testpdf.pdf" height="600" width="600"  type="application/pdf"></object>

Is there any cross-browser way to prevent the javascript embedded inside a PDF from running? 有没有跨浏览器的方法来阻止嵌入PDF的javascript运行?

Is there any cross-browser way to prevent the javascript embedded inside a PDF from running? 有没有跨浏览器的方法来阻止嵌入PDF的javascript运行?

No. Not if you use the object element. 不。如果使用object元素,则不会。 With the object element, you are instructing the browser to use the default PDF viewer for that browser. 使用object元素,您将指示浏览器对该浏览器使用默认的PDF查看器。 It may be a native viewer or it may be an OS level default viewer. 它可能是本机查看器,也可能是操作系统级别的默认查看器。 I suggest you rethink your solution. 我建议您重新考虑您的解决方案。 @Nirus suggests pdf.js and I'd agree but there are other HTML5-based viewers. @Nirus建议使用pdf.js,我同意,但还有其他基于HTML5的查看器。 Essentially, the only way to achieve any degree of cross-browser consistency is to control the way the PDF is displayed. 本质上,实现任何程度的跨浏览器一致性的唯一方法是控制PDF的显示方式。 You can't do that using the object tag. 您不能使用object标签来做到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM