【发布时间】:2014-06-18 04:30:48
【问题描述】:
我遇到了 IE 问题,当我动态创建 iframe、将其源设置为 pdf 并将其附加到文档时,iframe 的“onload/load”事件不会触发。
我需要监听该事件的原因是因为我需要隐藏 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;
但是,我的函数 framedContentLoaded 永远不会在 IE 中触发。
我创建了一个重现问题的小提琴:http://jsfiddle.net/s5TUU/
【问题讨论】:
-
您找到解决方案了吗?
-
@membersound,很遗憾,没有。
标签: javascript internet-explorer iframe