DocumentPictureInPicture: window 屬性

可用性有限

此特性不是基線特性,因為它在一些最廣泛使用的瀏覽器中不起作用。

實驗性: 這是一項實驗性技術
在生產中使用此技術之前,請仔細檢查瀏覽器相容性表格

安全上下文: 此功能僅在安全上下文(HTTPS)中可用,且支援此功能的瀏覽器數量有限。

DocumentPictureInPicture 介面的只讀屬性 window 返回一個 Window 例項,該例項代表畫中畫視窗內部的瀏覽上下文。

如果已使用 DocumentPictureInPicture.requestWindow() 打開了畫中畫視窗,則返回一個 Window 物件例項,否則返回 null

示例

js
const videoPlayer = document.getElementById("player");

// …

await window.documentPictureInPicture.requestWindow({
  width: videoPlayer.clientWidth,
  height: videoPlayer.clientHeight,
});

// …

const pipWindow = window.documentPictureInPicture.window;
if (pipWindow) {
  // Mute video playing in the Picture-in-Picture window.
  const pipVideo = pipWindow.document.querySelector("#video");
  pipVideo.muted = true;
}

規範

規範
文件畫中畫規範
# dom-documentpictureinpicture-window

瀏覽器相容性

另見