HTMLVideoElement: enterpictureinpicture event
Picture-in-Picture API
Picture-in-Picture API
The enterpictureinpicture event is fired when the HTMLVideoElement enters picture-in-picture mode successfully.
This event is not cancelable and does not bubble.
Syntax
Use the event name in addEventListener():
addEventListener("enterpictureinpicture", (event) => { })
Alternatively, assign to the event handler property of the interface:
onenterpictureinpicture = (event) => { }
Event type
A PictureInPictureEvent. Inherits from Event.
PictureInPictureEvent
Examples
These examples add an event listener for the HTMLVideoElement's enterpictureinpicture event, then post a message when that event handler has reacted to the event firing.
Using addEventListener():
const video = document.querySelector("#video");
const button = document.querySelector("#button");
function onEnterPip() {
console.log("Picture-in-Picture mode activated!");
}
video.addEventListener("enterpictureinpicture", onEnterPip);
button.onclick = () => {
video.requestPictureInPicture();
};
Using the onenterpictureinpicture event handler property (but note that this replaces other event listeners added using onenterpictureinpicture, if any):
const video = document.querySelector("#video");
const button = document.querySelector("#button");
function onEnterPip() {
console.log("Picture-in-Picture mode activated!");
}
video.onenterpictureinpicture = onEnterPip;
button.onclick = () => {
video.requestPictureInPicture();
};
Specifications
Browser compatibility
See also
- HTMLVideoElement
- Picture-in-Picture API