HTMLVideoElement: leavepictureinpicture event
Picture-in-Picture API
Picture-in-Picture API
The leavepictureinpicture event is fired when the HTMLVideoElement leaves picture-in-picture mode successfully.
This event is not cancelable and does not bubble.
Syntax
Use the event name in addEventListener():
addEventListener("leavepictureinpicture", (event) => { })
Alternatively, assign to the event handler property of the interface:
onleavepictureinpicture = (event) => { }
Event type
A PictureInPictureEvent. Inherits from Event.
PictureInPictureEvent
Examples
These examples add an event listener for the HTMLVideoElement's leavepictureinpicture 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 onExitPip() {
console.log("Picture-in-Picture mode deactivated!");
}
video.addEventListener("leavepictureinpicture", onExitPip);
button.onclick = () => {
if (document.pictureInPictureElement) {
document.exitPictureInPicture();
}
};
Using the onleavepictureinpicture event handler property (but note that this replaces other event listeners added using onleavepictureinpicture, if any):
const video = document.querySelector("#video");
const button = document.querySelector("#button");
function onExitPip() {
console.log("Picture-in-Picture mode deactivated!");
}
video.onleavepictureinpicture = onExitPip;
button.onclick = () => {
if (document.pictureInPictureElement) {
document.exitPictureInPicture();
}
};
Specifications
Browser compatibility
See also
- HTMLVideoElement
- Picture-in-Picture API