[英]How can I force a PDF to download as a fallback?
On a click event, I want to render a PDF inside an element, and I'm appending it in an object
tag. 在click事件中,我想在一个元素内呈现PDF,然后将其附加到一个
object
标签中。
As a fallback for older browsers, I'd like to make the PDF to download automatically. 作为旧版浏览器的后备产品,我想使PDF自动下载。 Here's what I'm working with
这就是我的工作
<div class="selected">
<object data="loader-resources/doc.pdf" type="application/pdf" class="loaded" width="100%" height="100%">
<p class="error">Your browser cannot display pdf within a website.</p>
</object>
</div>
I can't do this server-side, via Content Disposition in my HttpResponse header as it directs here , because I want the PDF to render on-page if the user's browser supports it. 我无法通过服务器的HttpResponse标头中的Content Disposition进行此操作 ,因为我希望PDF在用户浏览器支持的情况下在页面上呈现。
Any ideas? 有任何想法吗?
Old browser, what else work better than simple 旧的浏览器,还有什么比简单的浏览器更好
<a href="doc.pdf">download</a>
Then setup another route on the server for fallback. 然后在服务器上设置另一个路由以进行回退。
For not that old browser you may able to download the pdf as string and do(break in IE 9 & below): 对于不是那种旧的浏览器,您可以下载pdf作为字符串并执行(在IE 9及以下版本中中断):
<a href='data:application/pdf;content-disposition:attachment;filename=doc.pdf,' + pdfstring</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.