DocumentPictureInPicture

Limited availability

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

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

安全上下文: 此项功能仅在一些支持的浏览器安全上下文(HTTPS)中可用。

Document Picture-in-Picture APIDocumentPictureInPicture 接口是创建和处理文档画中画窗口的入口点。

它是通过 Window.documentPictureInPicture 属性访问的。

EventTarget DocumentPictureInPicture

实例属性

从其父接口 EventTarget 继承属性。

window 只读 实验性

返回一个 Window 实例,代表画中画窗口内的浏览上下文。

实例方法

从其父接口 EventTarget 继承方法。

requestWindow() 实验性

为当前主浏览环境打开画中画窗口。返回一个 Promise,其兑现一个 Window 实例,代表画中画窗口内的浏览环境。

事件

从其父接口 EventTarget 继承事件。

enter 实验性

当画中画窗口成功打开时触发。

示例

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

// ...

// 打开画中画窗口。
const pipWindow = await window.documentPictureInPicture.requestWindow({
  width: videoPlayer.clientWidth,
  height: videoPlayer.clientHeight,
});

// ...

请参阅 Document Picture-in-Picture API 示例获取完整的可运行演示(另请参阅完整的源代码)。

规范

Specification
Document Picture-in-Picture Specification
# documentpictureinpicture

浏览器兼容性

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
DocumentPictureInPicture
Experimental
enter event
Experimental
requestWindow
Experimental
disallowReturnToOpener option
Experimental
preferInitialWindowPlacement option
Experimental
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.

参见