0

How can I get the content of the body in an iFrame and store it in a new div? For example:

<div class="area">
    <iframe  id="e_iframe" class="pt">
        #document
        <html>
            <body>
                BODYContents
            </body>
        </html>
    </iframe>
</div>

Can I store the content BODYContents in:

<div id="myid"></div>

with JavaScript?

Noam Hacker
  • 4,671
  • 7
  • 34
  • 55
van abel
  • 181
  • 10
  • 1
    possible duplicate of [How to get the body's content of an iframe in Javascript?](http://stackoverflow.com/questions/926916/how-to-get-the-bodys-content-of-an-iframe-in-javascript) – Two-Bit Alchemist Mar 18 '14 at 15:56
  • this question is half of already answer above link but how to store in div tag. – Jaykumar Patel Mar 18 '14 at 16:07

1 Answers1

0

The following code should work for what you need:

var iframe = document.getElementById('e_iframe'),
    icontent = iframe.contentDocument || iframe.contentWindow.document,
    bodyEle = icontent.getElementsByTagName('body'),
    content = bodyEle[0].innerHTML;

document.getElementById('myid').innerHTML = content;
BenM
  • 52,573
  • 26
  • 113
  • 168