大网数据广告活动
Web 标准与前端开发

Document:pictureInPictureElement 属性

· 52CE 我爱测

Document 接口的 **`pictureInPictureElement`** 只读属性返回当前文档中以画中画模式呈现的 Element,如果没有使用画中画模式,则返回 `null`。

Picture-in-Picture API

Document 接口的 pictureInPictureElement 只读属性返回当前文档中以画中画模式呈现的 Element,如果没有使用画中画模式,则返回 null。

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

值

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

如果文档没有处于画中画模式的相关元素,则返回 null。例如,没有画中画元素,或者画中画元素来自 iframe 中。

示例

此示例展示了一个 exitPictureInPicture() 函数,该函数的运行由 pictureInPictureElement 的返回值决定。如果文档处于画中画模式(pictureInPictureElement 不是 null),Document.exitPictureInPicture() 将被运行以退出画中画模式。

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

规范

浏览器兼容性

参见

  • HTMLVideoElement.requestPictureInPicture()
  • HTMLVideoElement.disablePictureInPicture
  • Document.pictureInPictureEnabled
  • Document.exitPictureInPicture()
  • :picture-in-picture

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。