0

Good day to all.

I have this structure

  <html>

         <iframe>

                <div id="idd">Some Content</div>

         </iframe>       

         <script type="text/javascript">
                 function getIddContent()
                 {
                      //This is the part I ask about
                 }

                 var content = getIddContent();
         </script>
  </html>

I need to get the content of the div inside the content variable. Thank you for your time. If I use document.getElementById("idd").innerHTML it says that the div doesn't exist.

zozo
  • 8,230
  • 19
  • 79
  • 134
  • Try looking into this: http://stackoverflow.com/questions/926916/how-to-get-body-content-of-iframe-by-javascript – ysrb Jul 20 '11 at 11:52

1 Answers1

2

Use the following code

function getIddContent() {
    return window.frames[0].document.getElementById('idd').innerHTML;
}

But you probably have to include the iframe contents via the src attribute on the iframe.

zatatatata
  • 4,761
  • 1
  • 20
  • 41
  • I get permission denied... I forgot to mention the iframe is not on the same domain... is on the same server but I don't think that helps. – zozo Jul 20 '11 at 11:59
  • If it's not on the same domain, it's impossible to get access to the contents, because that violates the cross domain policy. Sorry. – zatatatata Jul 20 '11 at 12:03