大网数据广告活动
Web 标准与前端开发

HTMLIFrameElement

· 52CE 我爱测

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

HTML DOM

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

属性

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

  • HTMLIFrameElement.align
    • : 一个 String 指定了相对于当前上下文的对齐方式。
  • HTMLIFrameElement.allowfullscreen
    • : 一个 Boolean 标识了该内联 frame 是否愿意被全屏防止。详情请参考 Using full-screen mode 。
  • HTMLIFrameElement.contentDocument
    • : 返回一个 Document,该内联 frame 嵌套的浏览上下文中活跃的 document 对象。
  • HTMLIFrameElement.contentWindow
    • : 返回一个 WindowProxy,该嵌套的浏览上下文中的 window 代理。
  • HTMLIFrameElement.frameBorder
    • : 一个 String 标识了是否在 frame 之间创建边框。
  • HTMLIFrameElement.height
    • : 一个 String 反映着 height HTML 属性,标识了该 frame 的高度。
  • HTMLIFrameElement.longDesc
    • : 一个 String 包含着该 frame 的详细描述的 URI。
  • HTMLIFrameElement.marginHeight
    • : 一个 String ,该 frame 的外边距高度。
  • HTMLIFrameElement.marginWidth
    • : 一个 String ,该 frame 的外边距宽度。
  • HTMLIFrameElement.name
    • : 一个 String 反映着 name HTML 属性,包含着用来引用该 frame 的名字。
  • HTMLIFrameElement.referrerPolicy
    • : 一个 String 反映着 referrerpolicy HTML 属性,标识了获取关联资源时要使用哪个 referrer。
  • HTMLIFrameElement.sandbox
    • : 一个 DOMSettableTokenList 反映着 sandbox HTML 属性,指示着对嵌套内容额外的限制。
  • HTMLIFrameElement.scrolling
    • : 一个 String 指示着浏览器是否应该为该 frame 提供滚动条。
  • HTMLIFrameElement.src
    • : 一个 String 反映着 src HTML 属性,包含被嵌入内容的地址。
  • HTMLIFrameElement.srcdoc
    • : 一个 String ,表示该 frame 中要显示的内容。
  • HTMLIFrameElement.width
    • : 一个 String 反映着 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的可见性。这会影响资源分配和一些函数的资源占用率,如window.requestAnimationFrame。
  • HTMLIFrameElement.getVisible()
    • : 指示当前浏览器iframe的可见性。
  • HTMLIFrameElement.setActive()
    • : 设置当前iframe为活动 frame,对进程管理器如何划分优先级有影响。
  • HTMLIFrameElement.getActive()
    • : 指示当前浏览器iframe是否为当前活动的 frame。
  • HTMLIFrameElement.setInputMethodActive()
    • : 设置当前浏览器iframe是活动的输入法编辑器窗口而其他不是。当一个顶层应用希望激活一个窗口作为输入法编辑器(如键盘)时有用。
  • HTMLIFrameElement.setNfcFocus()
    • : 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 iframes 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 HTMLIFrameElement.findAll search has been carried out.
  • HTMLIFrameElement.clearMatch()
    • : Clears any content highlighted by HTMLIFrameElement.findAll or HTMLIFrameElement.findNext.

Event-related methods

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
    • : EventTarget.addEventListener, EventTarget.removeEventListener, and EventTarget.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 HTMLIFrameElement.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

Browser compatibility

See also

  • The HTML element implementing this interface: iframe

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。