I have the following HTML
<iframe id ="myIframe">
#document
<head>...</head>
<body>Text I want to get is here</body>
</iframe>
I only know the iframe's id. Using JavaScript, how can I extract the text from the body?
I have the following HTML
<iframe id ="myIframe">
#document
<head>...</head>
<body>Text I want to get is here</body>
</iframe>
I only know the iframe's id. Using JavaScript, how can I extract the text from the body?
Share Improve this question asked Oct 23, 2012 at 20:29 RhsRhs 3,31813 gold badges52 silver badges90 bronze badges 1- 1 is your iframe src from same domain or different? – Anoop Commented Oct 23, 2012 at 20:30
1 Answer
Reset to default 15Assuming your iframe is in the same domain as your HTML:
var myIFrame = document.getElementById("myIframe");
var content = myIFrame.contentWindow.document.body.innerHTML;
Otherwise you'll face some Same Origin Policy issues.