HTML DOM contentDocument 屬性
定義和用法
contentDocument 屬性能夠以 HTML 對象來返回 iframe 中的文檔。
可以通過所有標(biāo)準(zhǔn)的 DOM 方法來處理被返回的對象。
語法
iframeObject.contentDocument
實例
下面的例子可從載入 iframe 的文檔的第一個 <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>