Take the 2-minute tour ×

I'm trying to populate the id="review" tag in the html body with the contents of the iframe (using google as an example page). Instead of the contents of the iframe it returns this: [object HTMLDocument] . What am I doing wrong?

function googleReview()
    var iframeWindow = document.getElementById('google_window').contentDocument;

<iframe width="300px" height="80px" frameborder="0" scrolling="yes" name="google_window" id="google_window" src="http://google.com"></iframe>

<p id="review">Review Area</p>

<button type="button" onclick="googleReview()">Change Review</button>
share|improve this question
Unless the iframe is in the same domain, I don't think you'll be able to access its content. –  Matt Ball Mar 30 '11 at 18:22
tried iframeWindow.body.innerHTML? Your variable should be named iframeDocument since you are retrieving the window.document of the iframe and not the window itself. –  skarmats Mar 30 '11 at 18:25
@Matt - It returns "undefined" when I do it from the same domain, so I must be doing something wrong. I believe you're right that cross domain restrictions exist in this type of case. –  JMC Mar 30 '11 at 18:31
For the same domain, something like document.getElementById("review").innerHTML=iframeWindow.body.innerHTML; should work just fine. –  Matt Ball Mar 30 '11 at 18:35
Thanks Matt, that does work. –  JMC Mar 30 '11 at 18:47
add comment

1 Answer

up vote 1 down vote accepted

I don't think you can do that; when I add iframeWindow.innerHTML to get the contents I get a permission denied error. The issue is you're trying to access cross origin (domain) information.

share|improve this answer
add comment

Your Answer


