views:

639

answers:

1

I have a webpage where there is a texarea within a iframe. I need to read the value of this textarea from its child page javascript. Presently by using window.parent.getelementbyID().value in the javascript, I am able to fetch values of all controls in the parent page except the textarea within the iframe. Can anyone please give me any pointers to resolve this issue? Thanks in Advance, Archana

+1  A: 

If your iframe is in the same domain as your parent page you can access the elements using document.frames collection.

// replace myIFrame with your iFrame id
// replace myIFrameElemId with your iFrame's element id
// you can work on document.frames['myIFrame'].document like you are working on
// normal document object in JS
document.frames['myIFrame'].document.getElementById('myIFrameElemId')

If your iframe is not in the same domain the browser should prevent such access for security reasons.

RaYell
Thanks a lot for your suggestions.But the problem is that the frame id n frame name in my parent page changes in runtime, hence we cannot use the frame id/frame name for reference.Is there any other way Ra Yell?..
archana roy
Bith parent n child page are in same domain.
archana roy
If there is ony one iframe on your site you could try using `document,frames[0].document`. If there are more you need to change the index to some other value.
RaYell