HTMLElement : méthode showPopover()
Baseline 2025Newly available
Since January 2025, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
La méthode showPopover()
de l'interface HTMLElement
affiche un élément popover (c'est-à-dire un élément qui a un attribut popover
valide) en l'ajoutant à la couche supérieure.
Lorsque showPopover()
est appelée sur un élément avec l'attribut popover
qui est actuellement masqué :
- Un évènement
beforetoggle
est déclenché. - Le popover est affiché.
- L'évènement
toggle
est déclenché.
Si l'élément est déjà visible, une erreur est lancée.
Syntaxe
showPopover()
Paramètres
Aucun.
Valeur de retour
Aucune (undefined
).
Exceptions
InvalidStateError
DOMException
-
Lancée si le popover est déjà affiché.
Exemples
L'exemple suivant définit un comportement pour afficher un popover en appuyant sur une touche particulière du clavier.
HTML
<button popovertarget="mypopover">Basculer l'affichage du popover</button>
<p>
Vous pouvez appuyer sur la touche <kbd>h</kbd> de votre clavier pour afficher
le popover.
</p>
<div id="mypopover" popover="manual">Coucou</div>
JavaScript
const popover = document.getElementById("mypopover");
document.addEventListener("keydown", (event) => {
if (event.key === "h") {
popover.showPopover();
}
});
Résultat
must be provided
Spécifications
Specification |
---|
HTML # dom-showpopover |
Compatibilité des navigateurs
BCD tables only load in the browser