我有一个PHP页面,该页面显示了发票列表。单击这些发票中的任何一个显示其PDF文件。当用户单击任何发票时,嵌入式标签的SRC通过jQuery更改为适当的PDF文件。
效果很好,但奇怪的是,在野生动物园中的行为与Firefox中的行为不同。
在Firefox中,我只需单击发票 - > PDF显示。如果我在那之后立即单击另一张发票,然后再次单击第一张发票 - > PDF再次显示。
Safari:如果我重新单击发票,我会得到一个空白的PDF(嵌入式标签)。并下载该PDF会导致0KB文件。
似乎只发生在野生动物园中。
有人以前遇到过这个问题吗?
我已经搜索了很多尝试,但它仍然无法正常工作。
Html:
<div class="card-body">
<embed id="invoice_scan" src="" type="application/pdf" width="100%" height="400px" />
</div>
jQuery:
$('#invoice_scan').attr('src', '/docs/pdf_file1.pdf );
i have a php page which shows a list of invoices. clicking on any of those invoices shows its pdf file. When the user clicks on any invoice, the src of the embed tag is changed by jQuery to the appropriate pdf file.
Works very well, but strangely enough it behaves differently in safari then in firefox for instance.
In firefox i can just click on an invoice -> the pdf shows. if i right after that click on another invoice and after that click on the first invoice again -> the pdf shows again.
Safari: If i re-click an invoice, i get a blank pdf (embed tag). And downloading of that pdf results in a 0kb file.
Seems to only happen in safari.
Has anyone encountered this before and maybe know a solution to this issue?
i have googled and tried a lot but it's still not working.
Html:
<div class="card-body">
<embed id="invoice_scan" src="" type="application/pdf" width="100%" height="400px" />
</div>
jQuery:
$('#invoice_scan').attr('src', '/docs/pdf_file1.pdf );
发布评论
评论(4)
我遇到了这个问题,显示了使用Angular在对象标签中的PDF。
修复程序是从对象标签中删除type =“ application/pdf”。
I had this issue showing a pdf in an object tag using angular.
The fix was to remove type="application/pdf" from the object tag.
我对Safari 15.5有类似的问题,其中
&lt; object&gt;
标签。 PDF加载后,它将崩溃浏览器。我删除了type =“ Application \ pdf”
有条件地用于Safari。这似乎在起作用。替代选项是为PDF使用iframe。
为什么此代码在Macos Big Sur Safari上失败? /a>
I have a similar issue with Safari 15.5 with
<object>
tag. As soon as PDF gets loaded, it was crashing the browser. I removedtype="application\pdf"
conditionally for safari. That seems to be working.Alternate option would be use iFrame for PDF's.
Why is this code failing on MacOS Big Sur Safari?
即使使用
&lt; iframe/&gt;
也无法解决Safari的问题,但这将:Adobe的开源 pdf empi 解决了Safari的这些问题,请查看 pdf嵌入api docs 知道更多了解更多
查看 pdf嵌入API样品开始使用库
react.js :查看 pdf嵌入API反应样品
不要忘记在
index.html
文件中添加&lt; script/&gt;
标记文件even using
<iframe />
won't solve the problem for Safari but this will:Adobe's open source PDF Embed API solves these issues for Safari, check out PDF Embed API docs to know more
check out PDF Embed API samples to start using the library
React.js: check out PDF Embed API React samples
Don't forget to add
<script />
tag fromindex.html
file into your code我在Safari上也有类似的问题,但是删除
type =“ application/pdf”
属性没有修复它。我怀疑这与一些缓存问题有关。我最终在文件URL的末尾添加一个随机查询字符串。确实感觉就像是一个非常刺耳的环形框架解决方案,但可能并不总是实用的。
I had a similar issue on Safari, but removing the
type="application/pdf"
attribute didn't fix it. I have a suspicion that it is related to some caching issue.I ended up adding a random query string to the end of my file url each time it was pressed so that it would be fetched as a different file everytime. It does feel like a very hacky and roundabout solution and might not always be practical though.