Hi.
Im trying to access a string in a textbox which Is located within an iframe on the parent document but the iframe is linked to a source html file.
I know of
document.getElementById(‘textbox’).value
But because its within an iframe which is getting its data from another html file Im having difficulty.
Many thanks.
The following one-liner reaches from a child window up to the parent, and in to an iframe to retrieve the content.
window.opener.document.getElementsByTagName('iframe')[0].contentDocument.getElementById('content').innerHTML
Resulting in:
“<p>I am the iframe.</p>”
Breaking it down:
var parentDoc = window.opener.document;
var iframeDoc = parentDoc.getElementsByTagName('iframe')[0].contentDocument;
var iframeContent = iframeDoc.getElementById('content').innerHTML;