Is it possible for the parent of an iFRAME to extract the HTML of the iFRAME’s source document? I stumbled across a code faq that stated this was the way to do it:
var content = document.getElementById('myIFrame').document.innerHTML;
however this gave me undefined.
when I add the body reference like so:
var content = document.getElementById('myIFrame').document.body.innerHTML;
…I get the HTML of the parent instead of the iFRAME content that I wish to reference. I have also tried:
var content = document.getElementById('myIFrame').document.documentElement.innerHTML;
and
var content = document.getElementById('myIFrame').documentElement.innerHTML;
which results in the parent’s HTML and an ‘object null or not found’ exception, respectively.
Is this possible to do? and if so what is the proper path?
I am trying to capture as a string (with which i can do parsing & comparisons) the HTML (not the rendered content) of an I-FRAME(not a standard frame)'s content.
and as you can see there is no innerHTML–instead there is nothing between the opening and closing iframe tags. What you need to do is get a reference to the iframe window, which is done like this:
document.frames[“myIFrame”]
Then, since innnerHTML grabs whatever is between the opening and closing tag you mention, in that window you want to get: