最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Get Text from iframe - Stack Overflow

programmeradmin3浏览0评论

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

1 Answer 1

Reset to default 15

Assuming 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.

发布评论

评论列表(0)

  1. 暂无评论