files/en-us/web/api/htmldialogelement/closedby/index.md
{{ APIRef("HTML DOM") }}
The closedBy property of the
{{domxref("HTMLDialogElement")}} interface indicates the types of user actions that can be used to close the associated {{htmlelement("dialog")}} element. It sets or returns the dialog's closedby attribute value.
A string; possible values are:
any
closerequest
none
If the closedby attribute is absent or invalid, it falls back to the Auto state. In the Auto state:
<dialog> is opened with showModal(), it behaves as if: closedby="closerequest"<dialog> is opened by any other means, it behaves as if: closedby="none"closedBy usage<dialog closedby="any">
<p>
Closable using the <kbd>Esc</kbd> key, or by clicking outside the dialog
("light dismiss").
</p>
</dialog>
<pre id="log"></pre>
const logElement = document.getElementById("log");
function log(text) {
logElement.innerText = `${logElement.innerText}${text}\n`;
logElement.scrollTop = logElement.scrollHeight;
}
const dialog = document.querySelector("dialog");
dialog.showModal();
log(`closedBy: ${dialog.closedBy}`);
{{ EmbedLiveSample('Basic closedBy usage', '100%', '250px') }}
{{Specifications}}
{{Compat}}