我有一個文件x.xhtml
和另一個文件main.html
,其中我使用的是<iframe src=x.xhtml id=childframe>
。現在我想要做的是,在文件加載後,我想使用JavaScript獲取子框架的來源,即x.xhtml
。獲取iFrame的來源
我嘗試下面的代碼
function getChildInput() {
var iframe = document.getElementById('childFrame').contentWindow;
var childText = iframe.document.getElementById('childText');
alert(iframe.document.getElementsByTagName('html')[0].innerHTML);
}
,但它並沒有爲.xhtml
工作。如果我使用.html
代替,它工作正常。
這是XHTML的問題還是有任何其他方式從HTML以外的子框架獲取源代碼?
是擴展的唯一區別? – pimvdb 2011-03-19 11:16:59
是的!擴展是唯一的區別,當我正在更改相同的文件到x.html與工作正常 – imran 2011-03-19 11:21:15
看看控制檯你得到哪個錯誤消息。 – 2011-03-19 11:46:11