Window.frameElement - Web APIs 编辑

The Window.frameElement property returns the element (such as <iframe> or <object>) in which the window is embedded.

Note: Despite this property's name, it works for documents embedded within any embedding point, including <object>, <iframe>, or <embed>.

Syntax

const frameEl = window.frameElement

Value

The element which the window is embedded into. If the window isn't embedded into another document, or if the document into which it's embedded has a different origin, the value is null instead.

Example

const frameEl = window.frameElement;
// If we're embedded, change the containing element's URL to 'http://mozilla.org/'
if (frameEl) {
  frameEl.src = 'http://mozilla.org/';
}

Specifications

SpecificationStatusComment
HTML Living Standard
The definition of 'Window.frameElement' in that specification.
Candidate RecommendationInitial specification.

Browser compatibility

BCD tables only load in the browser

See also

  • window.frames returns an array-like object, listing the direct sub-frames of the current window.
  • window.parent returns the parent window, which is the window containing the frameElement of the child window.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:40 次

字数:2897

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文