DocumentPictureInPicture:window 属性

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

实验性: 这是一项实验性技术
在将其用于生产之前,请仔细检查浏览器兼容性表格

安全上下文: 此项功能仅在一些支持的浏览器安全上下文(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) {
  // 使画中画窗口中播放的视频静音。
  const pipVideo = pipWindow.document.querySelector("#video");
  pipVideo.muted = true;
}

规范

Specification
Document Picture-in-Picture Specification
# dom-documentpictureinpicture-window

浏览器兼容性

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
window
Experimental

Legend

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

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.

参见