1. Web
  2. Web APIs
  3. HTMLVideoElement
  4. leavepictureinpicture

HTMLVideoElement: leavepictureinpicture event

Limited availability

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

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 methods like addEventListener(), or set an event handler property.

js
addEventListener("leavepictureinpicture", (event) => { })
onleavepictureinpicture = (event) => { }

Event type

A PictureInPictureEvent. Inherits from Event.

Event PictureInPictureEvent

Event properties

This interface also inherits properties from its parent Event.

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():

js
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:

js
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

Specification
Picture-in-Picture
# eventdef-htmlvideoelement-leavepictureinpicture
Picture-in-Picture
# dom-htmlvideoelement-onleavepictureinpicture

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on by MDN contributors.

AltStyle によって変換されたページ (->オリジナル) /