HTMLIFrameElement

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

属性

继承了来自父类的属性,HTMLElement

HTMLIFrameElement.align 已弃用

一个 DOMString 指定了相对于当前上下文的对齐方式。

HTMLIFrameElement.allowfullscreen (en-US) 实验性

一个 Boolean (en-US) 标识了该内联 frame 是否愿意被全屏防止。详情请参考 Using full-screen mode (en-US)

HTMLIFrameElement.contentDocument (en-US) 只读

返回一个 Document,该内联 frame 嵌套的浏览上下文中活跃的 document 对象。

HTMLIFrameElement.contentWindow 只读

返回一个 WindowProxy,该嵌套的浏览上下文中的 window 代理。

HTMLIFrameElement.frameBorder 已弃用

一个 DOMString 标识了是否在 frame 之间创建边框。

HTMLIFrameElement.height (en-US)

一个 DOMString 反映着 height HTML 属性,标识了该 frame 的高度。

HTMLIFrameElement.longDesc 已弃用

一个 DOMString 包含着该 frame 的详细描述的 URI。

HTMLIFrameElement.marginHeight 已弃用

一个 DOMString ,该 frame 的外边距高度。

HTMLIFrameElement.marginWidth 已弃用

一个 DOMString ,该 frame 的外边距宽度。

HTMLIFrameElement.name (en-US)

一个 DOMString 反映着 name HTML 属性,包含着用来引用该 frame 的名字。

HTMLIFrameElement.referrerPolicy (en-US) 实验性

一个 DOMString 反映着 referrerpolicy HTML 属性,标识了获取关联资源时要使用哪个 referrer。

HTMLIFrameElement.sandbox (en-US)

一个 DOMSettableTokenList 反映着 sandbox HTML 属性,指示着对嵌套内容额外的限制。

HTMLIFrameElement.scrolling 已弃用

一个 DOMString 指示着浏览器是否应该为该 frame 提供滚动条。

HTMLIFrameElement.src (en-US)

一个 DOMString 反映着 src HTML 属性,包含被嵌入内容的地址。

HTMLIFrameElement.srcdoc (en-US)

一个 DOMString ,表示该 frame 中要显示的内容。

HTMLIFrameElement.width (en-US)

一个 DOMString 反映着 width HTML 属性,标识着该 frame 的宽度。

方法

继承了来自父类的属性,HTMLElement

浏览器 API 方法

为支持浏览器<iframe>的需求,HTMLIFrameElement已经扩展了一些新的方法来让<iframe>有更多的能力。他们并未成为规范(参见 Browser compatibility)。

导航方法

以下导航方法允许通过<iframe>的浏览历史进行导航。他们对于后退、前进、停止和重新加载按钮的实现而言是非常必须的。

HTMLIFrameElement.reload()

重新加载<iframe>元素内容。

HTMLIFrameElement.stop()

停止加载<iframe>元素内容。

HTMLIFrameElement.getCanGoBack()

指示是否可以后退。

HTMLIFrameElement.goBack()

改变<iframe>位置到上一个浏览历史记录的位置。

HTMLIFrameElement.getCanGoForward()

指示是否可以前进。

HTMLIFrameElement.goForward()

改变<iframe>位置到下一个浏览历史记录的位置。

管理方法

这个方法集管理浏览器<iframe>所用的资源。它们对于实现分页浏览程序非常有用。

HTMLIFrameElement.executeScript()

在浏览器<iframe>页面加载完成后执行指定的脚本。

HTMLIFrameElement.purgeHistory()

清理所有与浏览器<iframe>有关的资源(不包括 cookie)。

HTMLIFrameElement.setVisible()

修改浏览器<iframe>的可见性。这会影响资源分配和一些函数的资源占用率,如requestAnimationFrame

HTMLIFrameElement.getVisible()

指示当前浏览器<iframe>的可见性。

HTMLIFrameElement.setActive()

设置当前<iframe>为活动 frame,对进程管理器如何划分优先级有影响。

HTMLIFrameElement.getActive()

指示当前浏览器<iframe>是否为当前活动的 frame。

HTMLIFrameElement.setInputMethodActive()

设置当前浏览器<iframe>是活动的输入法编辑器窗口而其他不是。当一个顶层应用希望激活一个窗口作为输入法编辑器(如键盘)时有用。

HTMLIFrameElement.setNfcFocus() (en-US)

Firefox 操作系统 NFC API 的一部分,扩展了Browser API,这个集合设置浏览器<iframe>是否可以接收一个NFC事件。

音频相关方法

以下方法允许直接控制浏览器元素的声音。

HTMLIFrameElement.getVolume()

获取浏览器<iframe>当前音量。

HTMLIFrameElement.setVolume()

设置浏览器<iframe>当前音量。

HTMLIFrameElement.mute()

浏览器<iframe>播放的所有音频静音。

HTMLIFrameElement.unmute()

取消浏览器<iframe>播放所有音频的静音。

HTMLIFrameElement.getMuted()

指示当前浏览器<iframe>当前是否被静音。

Search methods

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

HTMLIFrameElement.findAll()

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()

Highlights the next or previous instance of a search result after a findAll() search has been carried out.

HTMLIFrameElement.clearMatch()

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().

HTMLIFrameElement.sendMouseEvent()

Sends a MouseEvent to the <iframe>'s content.

HTMLIFrameElement.sendTouchEvent()

Sends a TouchEvent to the <iframe>'s content. Note that this method is available for touch enabled devices only.

HTMLIFrameElement.addNextPaintListener()

Defines a handler to listen for the next MozAfterPaint event in the browser <iframe>.

HTMLIFrameElement.removeNextPaintListener()

Removes a handler previously set with addNextPaintListener().

Utility methods

Last, there are some utility methods, useful for apps that host a browser <iframe>.

HTMLIFrameElement.download()

Downloads a specified URL, storing it at the specified filename/path.

HTMLIFrameElement.getContentDimensions()

Retrieves the X and Y dimensions of the content window.

HTMLIFrameElement.getManifest()

Retrieves the manifest of an app loaded in the browser <iframe> and returns it as JSON.

HTMLIFrameElement.getScreenshot()

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()

Retrieves any structured microdata (and hCard and hCalendar microformat data) contained in the HTML loaded in the browser <iframe> and returns it as JSON.

HTMLIFrameElement.zoom()

Changes the zoom factor of the browser <iframe>'s content. This is particularly useful for zooming in/out on non-touch-enabled devices.

Specifications

Specification
HTML Standard
# htmliframeelement

Browser compatibility

BCD tables only load in the browser

See also

  • The HTML element implementing this interface: <iframe>