【问题标题】:IE9 not rendering iframe in ASP.NET applicationIE9 不在 ASP.NET 应用程序中呈现 iframe
【发布时间】:2012-01-10 19:00:26
【问题描述】:

我有一个父页面,它有一个iframe,还有一个javascript,它将创建一个表单,将其附加到 iframe,并在页面加载时通过 POST 将其提交到外部 URL。

然后将来自外部 URL 的内容加载到 iframe 中。这在除 IE9 之外的所有浏览器中都可以正常工作。 我尝试了'meta http-equiv="X-UA-Compatible" content="IE=8" ' 技巧,但这没有帮助。有时 iframe 会呈现内容,有时它不会在刷新时呈现。 javascript 中的调试语句显示它每次都在触发(每次页面加载),Fiddler 显示对外部 URL 的成功请求/响应。就好像 IE9 选择性地决定是否更新 DOM。

我还注意到,如果外部请求有任何延迟(需要几秒钟),则 iframe 内容永远不会呈现。有没有人在 IE9 上遇到过这种情况并有解决方案?

<iframe frameborder="0" height="600px" id="ifPage" runat="server" width="700px" />

<script type="text/javascript" language="javascript">
var alreadyrunflag = 0 //flag to indicate whether target function has already been run

if (document.addEventListener) {//FireFox or Sarafi
    document.addEventListener("DOMContentLoaded", function () { alreadyrunflag = 1; GetExternalPageContent() }, false)
}
else if (document.all && !window.opera) 
{//IE
    addLoadEvent(GetExternalPageContent)
}

function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    }
    else {
        window.onload = function () {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

function GetExternalPageContent() {

    var iframe = document.getElementsByTagName("iframe");
    if (iframe != null) {
        var uniqueString = "embFrame";
        iframe[0].contentWindow.name = uniqueString;
        var form = document.createElement("form");
        form.target = uniqueString;
        form.action = '<%=ExternalUrl %>';
        form.method = "POST";

        //parameter submitted to external URL to get appropriate content  
        var input = document.createElement("input");
        input.type = "hidden";
        input.name = "embParam";
        input.value = "paramValue1";
        form.appendChild(input);

        document.body.appendChild(form);
        form.submit();
    }
}
</script>

【问题讨论】:

  • Https链接在IE下使用IFRAME卡住了。你有吗?
  • 是的,“ExternalUrl”被评估为 HTTPS 站点

标签: asp.net iframe internet-explorer-9


【解决方案1】:

我只是想让人们知道这里的问题是 IE 不喜欢这样命名 iframe 内容窗口:

iframe[0].contentWindow.name = uniqueString

相反,name 属性必须在 iframe 标记本身内。没有 javascript 错误表明这一点,它只是没有始终如一地呈现。然后,当您需要动态引用 iframe 内容时,使用:

var iframe = window.frames['embFrame']

这样做解决了问题,现在 iframe 内容呈现一致。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多