HTML DOM contentDocument 屬性
定義和用法
contentDocument 屬性能夠以 HTML 對(duì)象來(lái)返回 iframe 中的文檔。
可以通過(guò)所有標(biāo)準(zhǔn)的 DOM 方法來(lái)處理被返回的對(duì)象。
語(yǔ)法
iframeObject.contentDocument
實(shí)例
下面的例子可從載入 iframe 的文檔的第一個(gè) <h2> 元素中提取文本:
<html>
<head>
<script type="text/javascript">
function getTextNode()
{
var x=document.getElementById("frame1").contentDocument
;
alert(x.getElementsByTagName("h2")[0].childNodes[0].nodeValue);
}
</script>
</head>
<body>
<iframe src="frame_a.htm" id="frame1"></iframe>
<br /><br />
<input type="button" onclick="getTextNode()" value="Get text" />
</body>
</html>