我從文本編輯器中忽略了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>
它不''元素的屬性...它是文檔 – charlietfl