一个iframe的contentDocument [英] contentDocument for an iframe
问题描述
contentDocument对iframe(甚至是旧的frame元素)来说究竟是什么?是否等同于html元素或body元素?
这是什么用?
所有浏览器都支持此属性?
What exactly does "contentDocument" represent for an iframe (or even the old "frame" element)? Is it equivalent to the "html" element or the "body" element ? What is it's use? And is this property supported across all the browsers?
推荐答案
contentDocument类型文档,只读,在DOM级别2中引入
如果有任何内容可用,则该框架包含的文档,否则为空。 p>
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.
从DOM iframe元素中,脚本可以通过以下方式访问包含的HTML页面的窗口对象contentWindow属性。 contentDocument属性指的是iframe中的文档元素(这相当于contentWindow.document),但IE8之前的Internet Explorer版本不支持。
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.
该页面或框架的文档包含
此属性在Windows Internet Explorer 8中是新的
the document this page or frame contains
This property is new in Windows Internet Explorer 8
所以要获得body元素的innerHTML可以使用
So to get the innerHTML of the body element you could use
iframe.contentDocument.getElementsByTagName(body)[0]
或
iframe.contentDocument.body
在今天的浏览器中。
这篇关于一个iframe的contentDocument的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!