文档:pictureInPictureElement 属性

可用性有限

此特性不是基线特性,因为它在一些最广泛使用的浏览器中不起作用。

Document 接口的只读 pictureInPictureElement 属性返回当前在此文档中以画中画模式显示的 Element,如果当前未使用画中画模式,则返回 null

尽管此属性是只读的,但即使在严格模式下修改它也不会抛出错误;设置器是一个空操作,将被忽略。

当前处于画中画模式的 Element 对象的引用。

如果文档没有关联的画中画元素,则返回 null。例如,没有画中画元素,或者该元素来自 iframe。

示例

此示例提供了一个名为 exitPictureInPicture() 的函数,该函数测试 pictureInPictureElement 返回的值。如果文档处于画中画模式(pictureInPictureElement 不为 null),则运行 Document.exitPictureInPicture() 以退出画中画模式。

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

规范

规范
画中画
# dom-documentorshadowroot-pictureinpictureelement

浏览器兼容性

另见