Window.frameElement

  • Revision slug: DOM/window.frameElement
  • Revision title: window.frameElement
  • Revision id: 54112
  • Created:
  • Creator: Potappo
  • Is current revision? No
  • Comment rewrited See also section.

Revision Content

{{ DomRef() }}

Summary

Returns the element (such as <iframe> or <object>) in which the window is embedded, or null if the window is top-level.

Syntax

var frameEl = window.frameElement;
  • frameEl is the element which the window is embedded into, or null if the window is top-level.

Example

var frameEl = window.frameElement;
// if we are inside a frame, then change it's URL to 'http://mozilla.org/'
if (frameEl)
  frameEl.src = 'http://mozilla.org/';

Notes

Note that despite its name, the property also works for documents inside <object> and other embedding points.

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.

Specification

{{ DOM0() }}


{{ languages( { "ja": "ja/DOM/window.frameElement", "pl": "pl/DOM/window.frameElement" } ) }}

Revision Source

<p>
{{ DomRef() }}
</p>
<h3 name="Summary"> Summary </h3>
<p>Returns the element (such as <code>&lt;iframe&gt;</code> or <code>&lt;object&gt;</code>) in which the window is embedded, or <code>null</code> if the window is top-level.
</p>
<h3 name="Syntax"> Syntax </h3>
<pre class="eval">var <i>frameEl</i> = window.frameElement;
</pre>
<ul><li> <code>frameEl</code> is the element which the window is embedded into, or <code>null</code> if the window is top-level.
</li></ul>
<h3 name="Example"> Example </h3>
<pre class="eval">var frameEl = window.frameElement;
// if we are inside a frame, then change it's URL to '<span class="nowiki">http://mozilla.org/</span>'
if (frameEl)
  frameEl.src = '<span class="nowiki">http://mozilla.org/</span>';
</pre>
<h3 name="Notes"> Notes </h3>
<p>Note that despite its name, the property also works for documents inside <code>&lt;object&gt;</code> and other embedding points.
</p>
<h3 name="See_also">See also</h3>
<ul><li> <code><a href="en/DOM/window.frames">window.frames</a></code> returns an array-like object, listing the direct sub-frames of the current window.
</li><li> <code><a href="en/DOM/window.parent">window.parent</a></code> returns the parent window, which is the window containing the <code>frameElement</code> of the child window.
</li></ul>
<h3 name="Specification"> Specification </h3>
<p>{{ DOM0() }}
</p><p><br>
</p>
<div class="noinclude">
</div>
{{ languages( { "ja": "ja/DOM/window.frameElement", "pl": "pl/DOM/window.frameElement" } ) }}
Revert to this revision