How to get the content from < iframe> with javascript

< iframe> shows the content of the file it loads. Then how to get the content it shows?

Here is an example for it:

<iframe id=”upload_target” name=”upload_target”></iframe>

javascript code is as below:

var xx = document.getElementById(‘MyIFrame’).contentDocument.body.innerHTML;
alert(xx);

I have tested it on IE8、firefox 3.6.12、Google Chrome 7.0.517.44, it all works.

One thought on “How to get the content from < iframe> with javascript

  1. Mia Post author

    If the above doesn’t work, try these two as below:

    document.getElementById(‘target_upload’).contentWindow.document.documentElement.innerHTML

    or

    document.getElementById(‘target_upload’).contentWindow.document.body.innerHTML

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *