window.frameElement

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

<iframe><object> のような)ウィンドウが埋め込まれた要素を返します。要素がトップレベルであるか異なるスクリプト生成元をもつ文書に埋め込まれるかのいずれかの場合は、 null を返します。

構文

frameEl = window.frameElement;
  • frameEl は、ウィンドウが埋め込まれた要素です。ウィンドウが別の文書に埋め込まれていない場合、または埋め込まれている文書が異なる生成元を持つ(例えば異なるドメインから設置されている)場合、これは null になります。

メモ: このプロパティの名前にもかかわらず、これは<object><iframe>、または <embed>を含むすべての埋め込みポイント内に埋め込まれた文書の役に立ちます。

js
var frameEl = window.frameElement;
// 埋め込みの場合、要素の URL が 'http://mozilla.org/' に変わります。
if (frameEl) {
  frameEl.src = "http://mozilla.org/";
}

仕様

Specification
HTML
# dom-frameelement-dev

ブラウザー互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
frameElement

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連項目

  • window.frames は、現在のウィンドウの直接のサブフレームを一覧する、配列のようなオブジェクトを返します。
  • window.parent は、子ウィンドウのframeElementを含むウィンドウである、親ウィンドウを返します。