繁体   English   中英

如何从父窗口访问iframe中存在的元素?

[英]How to access element present inside a iframe from parent window?

我有一个iframe。 我想访问iframe中存在的表。我想从iframe的父窗口访问它。 我写过像

Document.getElementById("table Id");

但是结果为空。 得到它的过程是什么? 谢谢


x=document.getElementById("iFrameId");
x.contentDocument.getElementById("tableId");

如果您可以使用jQuery,我想它会在所有浏览器中正常工作

$("#iFrameId").contents().find("#tableId")

您必须从iFrame的文档中选择元素。 根据Juan的评论,同时检查iFrame的名称和ID

var targetFrame = window.frames["nameOfIFrame"] || window.frames["iFrameId"];
targetFrame.document.getElementById("tableId");

编辑

我只是用以下方法对此进行了测试:

window.frames["fName"].document.getElementById("Adam").innerHTML

在Chrome控制台中,它从我的iframe中输出Adam div的html。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM