How can I access iframes using Javascript?

I have a webpage where there is a texaria inside the iframe. I need to read the value of this text field in its child javascript page. Currently, using window.parent.getelementbyID().value in javascript, I can retrieve the values โ€‹โ€‹of all the controls on the parent page except for the text area inside the iframe.

The frame id and frame name on my parent page change at runtime, so we cannot use the frame name / frame for reference.

+45
javascript dom iframe
Sep 21 '09 at 4:12
source share
2 answers

If you have HTML

 <form name="formname" .... id="form-first"> <iframe id="one" src="iframe2.html"> </iframe> </form> 

and javascript

 function iframeRef( frameRef ) { return frameRef.contentWindow ? frameRef.contentWindow.document : frameRef.contentDocument } var inside = iframeRef( document.getElementById('one') ) 

inside now a link to the document, so you can do getElementsByTagName('textarea') and whatever you want, depending on what's inside the iframe src.

+58
Sep 21 '09 at 4:20
source share

Using jQuery, you can use contents() . For example:

 var inside = $('#one').contents(); 
+16
Jul 03 '13 at 10:37
source share



All Articles