HTMLElement : méthode showPopover()

Baseline 2024

Newly available

Since April 2024, 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 (en-US).

Lorsque showPopover() est appelée sur un élément avec l'attribut popover qui est actuellement masqué :

  1. Un évènement beforetoggle est déclenché.
  2. Le popover est affiché.
  3. L'évènement toggle est déclenché.

Si l'élément est déjà visible, une erreur est lancée.

Syntaxe

js
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

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

js
const popover = document.getElementById("mypopover");

document.addEventListener("keydown", (event) => {
  if (event.key === "h") {
    popover.showPopover();
  }
});

Résultat

Spécifications

Specification
HTML Standard
# dom-showpopover

Compatibilité des navigateurs

BCD tables only load in the browser

Voir aussi