Document:pictureInPictureEnabled 属性

Limited availability

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

Document 接口的 pictureInPictureEnabled 只读属性表示画中画模式是否可用。

除非权限策略另有指定,否则画中画模式默认是可用的。

尽管这个属性是只读的,但是即使它被修改(甚至是在严格模式下),也不会抛出错误;setter 是无操作的并且将会被忽略。

一个布尔值,如果视频可以通过调用 HTMLVideoElement.requestPictureInPicture() 进入画中画模式并在浮动窗口中播放,则为 true。如果画中画模式不可用,则值为 false

示例

在此示例中,在 <video> 元素试图进入画中画模式之前,会检查 pictureInPictureEnabled 的值,为避免在该功能不可用时调用。

js
function requestPictureInPicture() {
  if (document.pictureInPictureEnabled) {
    videoElement.requestPictureInPicture();
  } else {
    console.log("你的浏览器目前无法使用画中画功能");
  }
}

规范

Specification
Picture-in-Picture
# ref-for-dom-document-pictureinpictureenabled

浏览器兼容性

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
pictureInPictureEnabled

Legend

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

Full support
Full support
No support
No support
See implementation notes.

参见