【问题标题】:onload event from iframe that is dynamically generated via ajax is not firing in IE通过 ajax 动态生成的 iframe 中的 onload 事件未在 IE 中触发
【发布时间】:2014-11-02 03:41:03
【问题描述】:

我有这个发送过滤器字段的 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

以及许多其他解决方案。

【问题讨论】:

    标签: c# javascript ajax asp.net-mvc-4 iframe


    【解决方案1】:

    我停止搜索如何使onload在IE中工作,并开始搜索如何检测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();
                    }
                }
            }
    }
    

    我在 iframe 的定义中保留了 onload 属性,以便它可以在 Chrome 中运行,然后在 onSuccess 事件中使用 onreadystatechange 事件,以便 IE 可以检测并按我的意愿工作。

    【讨论】:

      猜你喜欢
      • 2014-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多