首页 > 其他分享 >HTML DOM contentDocument 属性

HTML DOM contentDocument 属性

时间:2022-10-28 18:14:42浏览次数:50  
标签:contentDocument DOM HTML 文档 iframe 属性

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>

标签:contentDocument,DOM,HTML,文档,iframe,属性
From: https://www.cnblogs.com/Dongmy/p/16836980.html

相关文章