Ada*_*cer 5 javascript iframe internet-explorer
我有一个IE问题,当我动态创建iframe时,iframe的"onload/load"事件不会触发,将其源设置为pdf并将其附加到文档.
我需要监听事件的原因是因为我需要隐藏iframe直到帧加载,然后使用一些效果将其淡入视图.
我已经在我测试的每个浏览器(Chrome,Firefox,Safari,移动Safari)中都可以使用它,但它在IE8-> IE11中无效.
我已经看过很多关于IE如何不触发onload事件的帖子,而且根据我收集的内容,以下内容应该有效:
// listen for when the iframe's content has been loaded...
if (window.addEventListener)
iframe.addEventListener("load", framedContentLoaded, false);
else if (window.attachEvent)
iframe.attachEvent("onload", framedContentLoaded);
else
iframe.onload = framedContentLoaded;
Run Code Online (Sandbox Code Playgroud)
但是,我的功能framedContentLoaded
永远不会在IE中被解雇.
我创造了一个小提琴,重现了这个问题:http://jsfiddle.net/s5TUU/
一种简单的解决方案是使用 Google Viewer 查看 PDF。这不仅会显示 PDF,而且 onLoad 属性无疑也会起作用。Google Viewer: https: //docs.google.com/viewer我还应该注意,在网页上嵌入 PDF 的正确方法是使用嵌入标签,而不是 iframe。也许,您可以尝试使用 onreadystatechange 事件来代替?
归档时间: |
|
查看次数: |
2775 次 |
最近记录: |