【发布时间】:2011-04-27 18:00:47
【问题描述】:
好吧,伙计们,请耐心等待,这个设置很长。
我有一个简单的页面。它加载一个 iframe。该 iframe 内部是一个表单。我希望 iframe 中的表单通过 jQuery 与父页面交互。
这在 Firefox、Chrome 和 Safari 中可以正常工作。在这里自己看看:
http://dl.dropbox.com/u/58785/iframe-example/index.htm
但是,在 Internet Explorer 6/7/8/9 中,它不起作用。 load 事件触发,但 jQuery 无法获取 iframe 内元素的句柄。
我正在使用 jQuery 函数的第二个 'context' 参数来设置选择器的上下文,如下所示:var form = $('#myform'), this.contentDocument)
这就是batty。使用 IE9 中的 F12 开发人员工具,我可以在我的 JavaScript 中设置断点并查看 IE 如何评估 JavaScript。如果我将鼠标悬停在this 上,我可以看到它确实有一个contentDocument 属性。 但是,如果我将鼠标悬停在 this.contentDocument 上,它会告诉我它是未定义的。
因为它是未定义的,所以 jQuery 选择器不返回任何元素。同样,这仅在 IE 中。而且 IFRAME 在同一个域上,所以不是同源问题。
任何指针?
【问题讨论】:
-
你试过
contentWindow吗?见stackoverflow.com/questions/1477547/… -
@Roatin Marth - 是的,
this.contentWindow.document解决了所有问题。您能否将其发布为答案,以便获得您应得的代表?
标签: javascript jquery internet-explorer iframe