For the dialog element <dialog>
, is there some sort of "open" event that is fired when it is shown, either normally or as a modal?
The spec isn't totally clear on this, and MDN just lists a bunch of inherited events.
The close
event does fire, but I can't seem to get any sort of open
event.
Example HTML:
<dialog>
<h1>Oh hey, a dialog...</h1>
</dialog>
And in JavaScript:
document.querySelector('dialog').addEventListener('open', (e) => {
console.log(e);
});
document.querySelector('dialog').showModal();
beforetoggle
and toggle
eventsThis is now available via the beforetoggle
and toggle
events in Chromium v123: https://github.com/whatwg/html/pull/10091
No, there is no open
event.
The dialog has an open
property which can determine if it's opened or not, but unfortunately there's no event when this transitions.