2016-02-29 21 views
1

我從文本編輯器中忽略了iFrame的HTLM,現在我想要獲得iFrame的標題,但是我一直無法再次獲取iFrame的內容。獲取更新的iFrame的標題

var iFrame = document.getElementById('myframe'); 
var iFrameBody; 
if (iFrame.contentDocument) 
{ // FF 
    iFrameBody = iFrame.contentDocument.getElementsByTagName('html')[0]; 
} 
else if (iFrame.contentWindow) 
{ // IE 
    iFrameBody = iFrame.contentWindow.document.getElementsByTagName('html')[0]; 
} 
iFrameBody.innerHTML = x; 

console.log(iFrameBody.title); 

我已經試過iFrameBody.getElementsByTagName('title')

console.log(iFrameBody);給出:

<html> 
<head> 
    <title>my website</title> 
</head> 
<body> 
    <!--Add your heading tag below--> 

</body> 
</html> 
+1

它不''元素的屬性...它是文檔 – charlietfl

回答

0

這做工作

document.getElementsByTagName('iframe')[0].contentDocument.title 

退房this

+0

的屬性是的,它確實有效,是否有辦法從iFrameBody對象中獲取它,而不是再次獲取iframe的內容? –

+0

@KeithPower沒有我知道,但你爲什麼要這樣做? – Abdel