繁体   English   中英

通过ajax动态生成的iframe的onload事件未在IE中触发

[英]onload event from iframe that is dynamically generated via ajax is not firing in IE

我有这种ajax形式发送过滤字段:

@using (Ajax.BeginForm(Model.Action, Model.Controller, new AjaxOptions() { HttpMethod = "POST", InsertionMode = InsertionMode.Replace, OnBegin = "onBegin", OnSuccess = "onSuccess", OnComplete = "onComplete" }, new { id = "formTemplate" }))

当我们提交此表单时,它将返回部分视图:

//返回部分视图

 @model PDFModel

    <iframe id="rptIframe" frameborder="0" src="@Url.Action(Model.Action, Model.Controller, new { someItemID= Model.SomeItemID, someItemID2= Model.SomeItemID2 })#zoom=70"></iframe>

//

这是我的onSucess事件:

function onSuccess(result)
{
   $("#rptContainer").html(result);
}

当我将其插入html页面时,它会从iframe的src中触发Url.Action。此操作将返回一个水晶报告,该报告以PDF形式呈现在表单下方,在Chrome中效果很好。

我的问题是,当请求正常运行时,我正在运行加载gif,我使用iframe中的onload事件将其隐藏,但在IE中未触发onload事件,我该如何解决呢?

我已经尝试过类似的事情:

document.getElementById('frameRelatorio').setAttribute('onload', 'iframeLoad();');

var iframe = document.getElementById('frameRelatorio');

    if (iframe.attachEvent) {
        iframe.attachEvent('onload', iframeLoad);
    }
    else {
        iframe.onload = iframeLoad;
    }

onload="return someFunction();"   //at the iframe

和许多其他解决方案。

我停下来搜索如何使IE中的onload工作,并开始搜索如何检测iframe是否已完全加载,然后找到此页面:

http://community.sitepoint.com/t/determining-when-an-iframe-is-fully-loaded/4724/18

所以我适应了我的问题,它按预期工作

function onSuccess(result)
{
   $("#rptContainer").html(result);

      if ($.browser.msie) {
          var myiframe = document.getElementById('frameRelatorio');
          myiframe.onreadystatechange = function () {
          if (myiframe.readyState == 'complete') {
                    iframeLoad();
                }
            }
        }
}

我将onload属性保留在iframe的定义中,以便它可以在Chrome中运行,然后在onSuccess事件中使用onreadystatechange事件,以便IE可以根据需要检测和工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM