开发者

Getting source of iFrame

开发者 https://www.devze.com 2023-02-18 07:46 出处:网络
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 chil

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消