admin管理员组文章数量:1399968
I have an iframe. I want to access a table which present inside iframe.I want to access it from parent window of iframe. I have written JS like
Document.getElementById("table Id");
But the result e null. What is the process to get it? thanks
I have an iframe. I want to access a table which present inside iframe.I want to access it from parent window of iframe. I have written JS like
Document.getElementById("table Id");
But the result e null. What is the process to get it? thanks
Share Improve this question asked Dec 30, 2011 at 5:35 user1122379user1122379 191 gold badge2 silver badges4 bronze badges 4- 1 i think this is not possible nowadays, is it cross-domain? – Joseph Commented Dec 30, 2011 at 5:49
- possible duplicate of stackoverflow./questions/729577/… – Pencho Ilchev Commented Dec 30, 2011 at 5:49
- 1 @fskreuz that only the case when the iframe isn't on the same domain. Otherwise there is no problem to access elements in the iframe. – Andreas Köberle Commented Dec 30, 2011 at 21:42
- @user1122379 you should mention if the iframe is on the same domain or not, cause the answer to the question depends a lot on that fact. – Andreas Köberle Commented Dec 30, 2011 at 21:46
2 Answers
Reset to default 4
x=document.getElementById("iFrameId");
x.contentDocument.getElementById("tableId");
if you can use jQuery i guess it will work across browsers
$("#iFrameId").contents().find("#tableId")
You have to select the element from the iFrame's document. Per Juan's ment, check against both the name, and id of the iFrame
var targetFrame = window.frames["nameOfIFrame"] || window.frames["iFrameId"];
targetFrame.document.getElementById("tableId");
EDIT
I just tested this with the following:
window.frames["fName"].document.getElementById("Adam").innerHTML
in the Chrome console, and it output the html of the Adam
div from within my iframe.
本文标签: javascriptHow to access element present inside a iframe from parent windowStack Overflow
版权声明:本文标题:javascript - How to access element present inside a iframe from parent window? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744134045a2592310.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论