window.parent

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.

We’d love to hear your thoughts on the next set of proposals for the JavaScript language. You can find a description of the proposals here.
Please take two minutes to fill out our short survey.

概要

現在のウィンドウ、または、サブフレームの親ウィンドウへの参照を返します。

ウィンドウが親を持たない場合、parent プロパティは、それ自身への参照となります。

ウィンドウが <iframe><object> 、あるいは、<frame> で読み込まれた場合、その親ウィンドウは、ウィンドウを埋め込んだ要素が存在するウィンドウとなります。

構文

parentWindow = window.parent

js
if (window.parent !== window.top) {
  // 1 段下より深いところ
}

仕様書

関連情報

  • window.frameElement - window が埋め込まれた(<iframe> 要素などの)特定の要素を返す
  • window.top - 最上位ウィンドウへの参照を返す