gpt4 book ai didi

javascript - iframe 的 contentDocument

转载 作者:技术小花猫 更新时间:2023-10-29 12:36:14 24 4
gpt4 key购买 nike

对于 iframe(甚至旧的“frame”元素),“contentDocument”到底代表什么?它等同于“html”元素或“body”元素吗?它有什么用?所有浏览器都支持此属性吗?

最佳答案

w3.org

contentDocument of type Document, readonly, introduced in DOM Level 2 The document this frame contains, if there is any and it is available, or null otherwise.

MDN

From the DOM iframe element, scripts can get access to the window object of the included HTML page via the contentWindow property. The contentDocument property refers to the document element inside the iframe (this is equivalent to contentWindow.document), but is not supported by Internet Explorer versions before IE8.

msdn

the document this page or frame contains
This property is new in Windows Internet Explorer 8

因此,要获取 body 元素的 innerHTML,您可以使用

iframe.contentDocument.getElementsByTagName("body")[0]

iframe.contentDocument.body

在当今的浏览器中。

关于javascript - iframe 的 contentDocument,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6581803/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com