HTMLIFrameElement 接口提供了除 HTMLElement 之外的一些特殊属性和方法(当然也包括了继承自 HTMLElement 的部分)。这些方法用于操作内联frame元素的布局和展示。



一个 DOMString 指定了相对于当前上下文的对齐方式。
一个 Boolean 标识了该内联frame是否愿意被全屏防止。详情请参考 Using full-screen mode 。
HTMLIFrameElement.contentDocument 只读
返回一个 Document,该内联frame嵌套的浏览上下文中活跃的document对象。
HTMLIFrameElement.contentWindow 只读
返回一个 WindowProxy,该嵌套的浏览上下文中的window代理。
一个 DOMString 标识了是否在frame之间创建边框。
一个 DOMString 反映着 height HTML 属性,标识了该frame的高度。
一个 DOMString 包含着该frame的详细描述的URI。
一个 DOMString ,该frame的外边距高度。
一个 DOMString ,该frame的外边距宽度。
一个 DOMString 反映着 name HTML 属性,包含着用来引用该frame的名字。
一个 DOMString 反映着 referrerpolicy HTML 属性,标识了获取关联资源时要使用哪个referrer。
一个 DOMSettableTokenList 反映着 sandbox HTML 属性,指示着对嵌套内容额外的限制。
一个 DOMString 指示着浏览器是否应该为该frame提供滚动条。
一个 DOMString 反映着 src HTML 属性,包含被嵌入内容的地址。
一个 DOMString ,表示该frame中要显示的内容。
一个 DOMString 反映着 width HTML 属性,标识着该frame的宽度。


Inherits properties from its parent, HTMLElement.

Browser API methods

To support the requirement of a browser <iframe>, HTMLIFrameElement has been extended with new methods that give the <iframe> some super powers. These are non-standard (see Browser compatibility.)

The following navigation methods allow navigation through the browsing history of the <iframe>. They are necessary to be able to implement back, forward, stop, and reload buttons.

Allows reloading of the <iframe> element content.
Allows stopping of the <iframe>'s content loading.
Indicates whether it's possible to navigate backwards.
Changes the location of the <iframe> for the previous location in its browsing history.
Indicates whether it's possible to navigate forward.
Changes the location of the <iframe> for the next location in its browsing history.

Management methods

The next set of methods manage the resources used by a browser <iframe>. These are especially useful for implementing tabbed browser application.

Allows a specified script to be executed against a page loaded in the browser <iframe>.
Clears all the resources (cookies, localStorage, cache, etc.) associated with the browser <iframe>.
Changes the visibility state of a browser <iframe>. This can influence resource allocation and some function usage such as requestAnimationFrame.
Indicates the current visibility state of the browser <iframe>.
Sets the current <iframe> as the active frame, which has an effect on how it is prioritized by the process manager.
Indicates whether the current browser <iframe> is the currently active frame.
Sets the current browser <iframe> as an active IME window and other iframes as non-active IME windows. Useful when a top level app wants to activate a window as an IME (Input Method Editor, like a keyboard.)
HTMLIFrameElement.setNfcFocus() 只支持Gecko移动设备(Gecko2.2+以上)
Part of the Firefox OS NFC API, extending the Browser API, this sets whether a browser <iframe> can receive an NFC event.

The following methods allow direct control of sound in the browser element.

HTMLIFrameElement.getVolume() 只支持Gecko移动设备(Gecko2.5+以上)
Gets the current volume of the browser <iframe>.
HTMLIFrameElement.setVolume() 只支持Gecko移动设备(Gecko2.5+以上)
Sets the current volume of the browser <iframe>.
HTMLIFrameElement.mute() 只支持Gecko移动设备(Gecko2.5+以上)
Mutes any audio playing in the browser <iframe>.
HTMLIFrameElement.unmute() 只支持Gecko移动设备(Gecko2.5+以上)
Unmutes any audio playing in the browser <iframe>.
HTMLIFrameElement.getMuted() 只支持Gecko移动设备(Gecko2.5+以上)
Indicates whether the browser <iframe> is currently muted.

Search methods

New methods are provided to allow programmatic searches of browser <iframe>s to be carried out.

HTMLIFrameElement.findAll() 只支持Gecko移动设备(Gecko2.5+以上)
Searches for a string in a browser <iframe>'s content; if found, the first instance of the string relative to the caret position will be highlighted.
HTMLIFrameElement.findNext() 只支持Gecko移动设备(Gecko2.5+以上)
Highlights the next or previous instance of a search result after a findAll() search has been carried out.
HTMLIFrameElement.clearMatch() 只支持Gecko移动设备(Gecko2.5+以上)
Clears any content highlighted by findAll() or findNext().

In order to manage the browser <iframe>'s content, many new events were added (see below). The following methods are used to deal with those events:

The <iframe> gains support for the methods of the EventTarget interface
addEventListener(), removeEventListener(), and dispatchEvent().
Sends a MouseEvent to the <iframe>'s content.
Sends a TouchEvent to the <iframe>'s content. Note that this method is available for touch enabled devices only.
Defines a handler to listen for the next MozAfterPaint event in the browser <iframe>.
Removes a handler previously set with addNextPaintListener().

Utility methods

Last, there are some utility methods, useful for apps that host a browser <iframe>.
Downloads a specified URL, storing it at the specified filename/path.
Retrieves the X and Y dimensions of the content window.
HTMLIFrameElement.getManifest() 只支持Gecko移动设备(Gecko2.5+以上)
Retrieves the manifest of an app loaded in the browser <iframe> and returns it as JSON.
Takes a screenshot of the browser <iframe>'s content. This is particularly useful to get thumbnails of tabs in a tabbed browser app.
HTMLIFrameElement.getStructuredData() 只支持Gecko移动设备(Gecko2.5+以上)
Retrieves any structured microdata (and hCard and hCalendar microformat data) contained in the HTML loaded in the browser <iframe> and returns it as JSON.
Changes the zoom factor of the browser <iframe>'s content. This is particularly useful for zooming in/out on non-touch-enabled devices.


Specification Status Comment
Referrer Policy
referrer attribute
Working Draft Added the referrerPolicy property.
WHATWG HTML Living Standard
Living Standard The following property has been added: allowFullscreen.
Recommendation The following properties are now obsolete: scrolling, marginWidth, marginHeight, longDesc, frameBorder, and align.
The following properties have been added: srcdoc, sandbox, and contentWindow.
Document Object Model (DOM) Level 2 HTML Specification
Recommendation The contentDocument property has been added.
Document Object Model (DOM) Level 1 Specification
Recommendation Initial definition.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support (Yes) 1.0 (1.7 or earlier) (Yes) (Yes) (Yes)
srcdoc 4 25 (25) ? ? ?
sandbox 4 17 (17)[1] ? ? ?
contentDocument (Yes) (Yes) 8.0[3] (Yes) (Yes)
contentWindow ? ? (Yes) ? ?
allowFullScreen 17 -webkit[4] 9.0 (9.0) -moz
18.0 (18.0)
未实现 未实现 未实现
referrerPolicy 未实现 50 (50) 未实现 未实现 未实现
Browser API methods 未实现 未实现[5] 未实现 未实现 未实现
Feature Android Firefox Mobile (Gecko) Firefox OS (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support (Yes) 1.0 (1.0) 1.0.1 (Yes) (Yes) (Yes)
srcdoc 4 25.0 (25) 1.1 ? ? ?
sandbox 4 17.0 (17)[1] 1.0.1 ? ? ?
seamless 4 未实现 未实现 ? ? ?
contentDocument (Yes) (Yes) 1.0.1 ? (Yes) (Yes)
contentWindow ? ? 1.0.1 ? ? ?
allowFullScreen 17 -webkit[4] 9.0 (9.0) -moz
18.0 (18.0)
1.0.1 未实现 未实现 未实现
referrerPolicy 未实现 50.0 (50) 2.5 未实现 未实现 未实现
Browser API methods 未实现 未实现 1.0.1[2] 未实现 未实现 未实现
  • [1] Previously, the type of sandbox was a DOMString instead of a DOMSettableTokenList. This has been fixed with Gecko 29.0 (Firefox 29 / Thunderbird 29 / SeaMonkey 2.26)) (bug 845067). Other browsers may still implement the property as DOMString since it was a late change in the specification.
  • [2] Requires privileged app, and browser and/or embed-apps permissions, depending on what you want to do. See Using the Browser API for more details. Most of the proprietary Browser API methods are supported from Firefox OS 1.0.1 onwards; they are marked where this is not the case.
  • [3] For older version use HTMLIFrameElement.contentWindow.document instead.
  • [4] Daily test builds only.
  • [5] Supported in chrome code only.

See also

  • The HTML element implementing this interface: <iframe>


 此页面的贡献者: harttle
 最后编辑者: harttle,