W3cubDocs

/DOM

window.frameElement

Returns the element (such as <iframe> or <object>) in which the window is embedded, or null if the element is either top-level or is embedded into a document with a different script origin; that is, in cross-origin situations.

Syntax

frameEl = window.frameElement;
  • frameEl is 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 (such as having been located from a different domain), this is null.

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

Example

var 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

Specification Status Comment
HTML Living Standard
The definition of 'Window.frameElement' in that specification.
Working Draft Initial specification.

Browser compatibility

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support 4? (Yes) 1.0 (1.7 or earlier) 5.5? 12.1? 4?
Feature Android Edge Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support ? (Yes) 1.0 (1.7 or earlier) ? ? ?

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.

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/window/frameElement