Document: pictureInPictureElement プロパティ

Document.pictureInPictureElement は読み取り専用プロパティで、 この文書内のピクチャインピクチャモードで現在表示されている Element を返します。ピクチャインピクチャモードが現在使用されていない場合は null を返します。

このプロパティは読み取り専用ですが、(厳格モードであっても)変更されても例外は発生しません。セッターは何もせず、無視されます。

現在ピクチャインピクチャモードになっている Element オブジェクトへの参照です。現在この document でピクチャインピクチャモードが使用されていない場合、返される値は null です。

この例では pictureInPictureElement が返す値を検査する関数 exitPictureInPicture() を表示しています。現在の文書がピクチャインピクチャモードでない(pictureInPictureElementnull である)場合、 Document.exitPictureInPicture() を実行してピクチャインピクチャモードを終了します。

js
function exitPictureInPicture() {
  if (document.pictureInPictureElement) {
    document.exitPictureInPicture();
  }
}

仕様書

Specification
Picture-in-Picture
# ref-for-dom-documentorshadowroot-pictureinpictureelement①⑤

ブラウザーの互換性

BCD tables only load in the browser

関連情報