IE浏览器中的iFrame OnLoad事件在Tapestry Zone更新后未触发

时间:2014-02-25 10:21:03

标签: javascript internet-explorer iframe onload

我有一个Tapestry区域,里面是<iframe>元素。当iframe完成加载时,我想要运行一个简单的JS函数(只是隐藏并启用一些东西,没什么特别的东西)。

在chrome和firefox中,它运行得很好,但我遇到了IE 9的问题。

function afterExportLoad() {
    // hide throbber gif
    // enable submit button
}

所以,从本质上讲,我尝试将它绑定到iframe(内联)

<iframe onload="afterExportLoad()" .../>

通过PrototypeJS

exportFrame.observe('load', afterExportLoad);

通过原生JS

if (window.addEventListener) {
    exportFrame.addEventListener("load", afterExportLoad, false);
} else if (window.attachEvent) {
    exportFrame.attachEvent("onload", afterExportLoad);
} else {
    exportFrame.onload = afterExportLoad;
}

使用上面的任何方式,它适用于IE以外的所有方式,但在IE中,加载iframe后,gif被“冻结”,按钮仍然被禁用。

有没有办法让它在IE9(以及可能的任何其他IE版本)中运行?

谢谢:)

1 个答案:

答案 0 :(得分:0)

所以,我正在摆弄一下并得到这个解决方案:

在功能

中添加了浏览器检查
function afterExportLoad() {
    if (document.getElementsByName('downloadFrame').length > 0) {
        var exportFrame = document.getElementsByName('downloadFrame')[0];

        if ((Prototype.Browser.IE && exportFrame.readyState == "complete") || (!Prototype.Browser.IE)) {
            // my stuff
        }
    }
}

更改了活动

<iframe onreadystatechange="afterExportLoad();" ...>

在另一个侦听区域更新的函数中,其中iframe是

if (document.getElementsByName('downloadFrame').length > 0) {
        var exportFrame = document.getElementsByName('downloadFrame')[0];
        if (!Prototype.Browser.IE) {
            exportFrame.stopObserving('readystatechange', exportLoad);
            exportFrame.onload = exportLoad;
        }
    }

如果any1提出了更好的解决方案,请告诉我:)

相关问题