CKTIS / HTML
closedby: decide how a dialog may close
Separate automatic dismissal from explicit application controls.
Version: HTML Living Standard
Syntax
<dialog closedby="none">...</dialog>On a dialog, closedby chooses permitted automatic closing actions. any includes outside clicks and close requests; closerequest includes close requests such as Escape but not outside-click dismissal; none disables automatic user dismissal. Missing or invalid values use the auto state: a modal dialog permits close requests, whereas a nonmodal dialog does not automatically close.
This does not disable deliberate application actions. Both close() and requestClose() remain available; the latter raises the cancelable cancellation event and ignores the closedby restriction. Always provide an accessible explicit exit when automatic dismissal is disabled. Do not remove the open attribute manually as a substitute for the proper closing methods.
The fixture opens a modal dialog, presses Escape while dismissal is disabled, then changes the setting and presses Escape again. Chromium 145 kept the first dialog open and closed it on the second request. The example checks the DOM capability and keeps an explicit close button; this newer attribute must not be assumed to work in every browser.
Examples
<!doctype html><meta charset="utf-8">
<dialog id="dialog" closedby="none"><p>Press Escape twice.</p><button id="exit" type="button">Close explicitly</button></dialog>
<output id="result"></output><script>
const dialog = document.querySelector('#dialog');
document.querySelector('#exit').onclick = () => dialog.close();
if (!('closedBy' in dialog)) {
document.querySelector('#result').textContent = 'closedby unsupported; explicit close remains available';
} else {
let count = 0, firstOpen;
document.addEventListener('keydown', event => {
if (event.key !== 'Escape') return;
count += 1;
if (count === 1) setTimeout(() => { firstOpen = dialog.open; dialog.closedBy = 'closerequest'; }, 0);
});
dialog.addEventListener('close', () => {
document.querySelector('#result').textContent = 'none-open=' + firstOpen + '; closerequest-open=' + dialog.open;
});
}
dialog.showModal();
</script>Result
none-open=true; closerequest-open=false
The test sends two actual keyboard events to the isolated page and verifies the open state after each.