简体   繁体   中英

Prevent embedded PDF <object> from opening print dialog

In my application I'm embedding PDFs from unknown sources in an HTML object tag. This works great in most cases, but sometimes a PDF will have embedded javascript instructing the PDF to print when it opens. When these PDFs load they open the print dialog, which is a very frustrating user experience.

This is what my PDF object looks like.

<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?

Is there any cross-browser way to prevent the javascript embedded inside a PDF from running?

No. Not if you use the object element. With the object element, you are instructing the browser to use the default PDF viewer for that browser. 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. Essentially, the only way to achieve any degree of cross-browser consistency is to control the way the PDF is displayed. You can't do that using the object tag.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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