iframe / jquery .toggle无法在Safari中隐藏.pdf [英] iframe / jquery .toggle fails to hide .pdf in Safari
问题描述
我有一个带有pdf src的iFrame。
单击按钮时会显示。
当我点击一个按钮时,它被隐藏。
I have an iFrame with a pdf src. When I click a button it is shown. When I click a button it is hidden.
它使用jquery编码为函数.toggle(简化):
It is coded as a function using jquery .toggle (simplified):
<script>
function showpdf() {
$('.showpdf').toggle();
}
</script>
<div class="showpdf" style="display:none">
<iframe class="showpdf" src="file.pdf" style="display:none;">
</iframe>
</div>
<div class="showpdf" style="display:none">Hide PDF</div>
<div class="showpdf" style="display:block">Show PDF</div>
这在IE,Chrome,FF中运行良好...
但在Safari中, pdf不会隐藏。
This works fine in IE, Chrome, FF... But in Safari, the pdf does not hide.
JSFiddle: http:// jsfiddle。 net / hT97Z /
JSFiddle: http://jsfiddle.net/hT97Z/
PS:任何人都可以解释为什么它与onLoad,onDomReady根本不起作用?
PS: can anyone explain why it does not work at all with onLoad, onDomReady?
推荐答案
以下是解决方案:
- 在隐藏的iframe中预加载.pdf
- 切换iframe和以前的可见性
- 使用jquery将src添加到原始iframe
JS-Fiddle: http://jsfiddle.net/hT97Z/3/
JS-Fiddle: http://jsfiddle.net/hT97Z/3/
通过这种方式,.pdf的加载与切换功能一起被隔离。
In this way the loading of the .pdf is isolated from the toggle function all together.
添加到函数的代码:
function showpdf() { $('.showpdf').toggle(); $('#theframe').attr('src','the.pdf'); }
添加的html:
<iframe style="display:none;" src="the.pdf"></iframe>
这篇关于iframe / jquery .toggle无法在Safari中隐藏.pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!