DocumentPictureInPicture:enter 事件

Limited availability

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

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

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

DocumentPictureInPicture 接口的 enter 事件在画中画窗口成功打开时触发。

语法

在诸如 addEventListener() 之类的方法中使用事件名称,或设置事件处理器属性。

js
addEventListener("enter", (event) => {});

onenter = (event) => {};

事件类型

示例

js
documentPictureInPicture.addEventListener("enter", (event) => {
  const pipWindow = event.window;
  console.log("视频播放器已进入画中画窗口");

  const pipMuteButton = pipWindow.document.createElement("button");
  pipMuteButton.textContent = "已静音";
  pipMuteButton.addEventListener("click", () => {
    const pipVideo = pipWindow.document.querySelector("#video");
    if (!pipVideo.muted) {
      pipVideo.muted = true;
      pipMuteButton.textContent = "未静音";
    } else {
      pipVideo.muted = false;
      pipMuteButton.textContent = "已静音";
    }
  });

  pipWindow.document.body.append(pipMuteButton);
});

规范

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

浏览器兼容性

BCD tables only load in the browser

参见