跳转到主要内容

Window: frameElement property

{{ApiRef("HTML DOM")}}

The Window.frameElement property returns the element (such as {{HTMLElement("iframe")}}iframe or {{HTMLElement("object")}}object) in which the window is embedded.

[!NOTE]NOTE: Despite this property's name, it works for documents embedded within any embedding point, including {{HTMLElement("object")}}object, {{HTMLElement("iframe")}}iframe, or {{HTMLElement("embed")}}embed.

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 {{glossary("origin")}}origin, the value is null instead.

Examples

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

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also

  • {{domxref("window.frames")}}frames returns an array-like object, listing the direct sub-frames of the current window.
  • {{domxref("window.parent")}}parent returns the parent window, which is the window containing the frameElement of the child window.