javascript - How to access element present inside a iframe from parent window? - Stack Overflow

I have an iframe. I want to access a table which present inside iframe.I want to access it from parent

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
Add a ment  | 

2 Answers 2

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744134046a4559972.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信