1

我的应用程序的弹出窗口中有一个 ajax 样式的表单。我使用带有目标 iframe 的表单,然后在 iframe.load() 函数上,获取内容并将它们显示回我的弹出窗口。

这适用于 IE9、Chrome、Firefox:

 $("iframe[name=addpart-iframe]").load(function () {
            //FF and IE fire the load when the popup first load, chrome does not. This kips the first onload where no submit has happened yet
               if (firstLoad == true) {
                   firstLoad = false;
                   return;
               }


               var response = this.contentDocument.body.innerHTML;
               $("#AddForm").html(response);


           });       

这很好用,除了在 IE7 中。当我查看 this.contentDocument.body 时——调试器说 body 不是一个有效的属性。我看外面的html,我的iframe此时也是空的。不知道为什么!

4

1 回答 1

2

contentDocument属性指的是 iframe 内的文档元素(相当于contentWindow.document),但 IE8 之前的 Internet Explorer 版本不支持该属性。

对于 IE 8 之前的早期版本,可以使用contentWindow属性。

var response;

if (this.contentDocument) {
    response = this.contentDocument.body.innerHTML;
} else {
    response = this.contentWindow.document.body.innerHTML;
}
于 2012-07-25T15:14:44.943 回答