DocumentPictureInPicture: enter event
Document Picture-in-Picture API
Document Picture-in-Picture API
The enter event of the DocumentPictureInPicture interface is fired when the Picture-in-Picture window is successfully opened.
Syntax
Use the event name in addEventListener():
addEventListener("enter", (event) => { })
Alternatively, assign to the event handler property of the interface:
onenter = (event) => { }
Event type
A DocumentPictureInPictureEvent.
Examples
documentPictureInPicture.addEventListener("enter", (event) => {
const pipWindow = event.window;
console.log("Video player has entered the pip window");
const pipMuteButton = pipWindow.document.createElement("button");
pipMuteButton.textContent = "Mute";
pipMuteButton.addEventListener("click", () => {
const pipVideo = pipWindow.document.querySelector("#video");
if (!pipVideo.muted) {
pipVideo.muted = true;
pipMuteButton.textContent = "Unmute";
} else {
pipVideo.muted = false;
pipMuteButton.textContent = "Mute";
}
});
pipWindow.document.body.append(pipMuteButton);
});
Specifications
Browser compatibility
See also
- Document Picture-in-Picture API
- Using the Document Picture-in-Picture API