访问嵌套 Iframe 的内容

Access the content of a nested Iframe

我正在创建一个应用程序,我想在其中访问嵌套 iframe 的内容。 假设我有一个页面 test.aspx 现在有一个 iframe 说 iframe1。而这个iframe的内容是另一个iframe。说 iframe2 所以它是一个嵌套的 iframe。 现在我想访问 iframe2 的内容。 我们如何访问第二个 iframe 的内容,因为我必须在第二个 iframe 中搜索一些文本。 我只想使用 javascript 或 jquery 访问 iframe。

终于找到解决办法了。

document.getElementById('iframe1').contentWindow.document.getElementById('iframe2').contentWindow;

并为 innerHTML 使用

frameElement.contentDocument.activeElement

var iframeFound = document.getElementById('iframe1').contentWindow.document.getElementById('iframe2').contentWindow;
         var   ifrme = iframeFound.frameElement.contentDocument.activeElement;