HTML DOM contentDocument 属性

https://www.jb51.net/w3school/htmldom/prop_iframe_contentDocument.htm

contentDocument 属性能够以 HTML 对象来返回 iframe 中的文档。

下面的例子可从载入 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>
posted @ 2022-10-28 18:02  yinghualeihenmei  阅读(55)  评论(0编辑  收藏  举报