iframe 的 contentDocument [英] contentDocument for an iframe

查看:27
本文介绍了iframe 的 contentDocument的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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?

推荐答案

w3.org

Document 类型的 contentDocument,只读,在 DOM Level 2 中引入此框架包含的文档(如果有并且可用),否则为 null.

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

从 DOM iframe 元素,脚本可以通过 contentWindow 属性访问包含的 HTML 页面的 window 对象.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.

msdn

此页面或框架包含的文档
此属性是 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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆