I have a file x.xhtml
and another file main.html
, in which I am using <iframe src=x.xhtml id=childframe>
. Now what I want to do is, after the file is loaded, I want to get the source of the child frame, i.e x.xhtml
, using JavaScript.
I tried the following code
function getChildInput() {
var iframe = document.getElementById('childFrame').contentWindow;
var childText = iframe.document.getElementById('childText');
ale开发者_开发技巧rt(iframe.document.getElementsByTagName('html')[0].innerHTML);
}
but it didn't work for .xhtml
. If I am using .html
instead, it works fine.
Is this a problem with XHTML or is there any other way of getting the source from the child frame other than HTML?
Try alert(iframe.document.body.innerHTML);
or
var doc_iframe = document.getElementsByName("myFrame")[0].contentWindow.document;
HTH
Ivo Stoykov
Try using the documentElement property:
alert(iframe.document.documentElement.innerHTML);
精彩评论