大网数据广告活动
Web 标准与前端开发

HTMLDialogElement: closedBy property

· 52CE 我爱测

The **`closedBy`** property of the HTMLDialogElement interface indicates the types of user actions that can be used to close the associated dialog element. It sets or returns the dialog's `closedby` attribute value.

HTML DOM

The closedBy property of the HTMLDialogElement interface indicates the types of user actions that can be used to close the associated dialog element. It sets or returns the dialog's closedby attribute value.

Value

A string; possible values are:

  • any
    • : The dialog can be dismissed with a light dismiss user action, a platform-specific user action, or a developer-specified mechanism.
  • closerequest
    • : The dialog can be dismissed with a platform-specific user action or a developer-specified mechanism.
  • none
    • : The dialog can only be dismissed with a developer-specified mechanism.

Default behavior

If the closedby attribute is absent or invalid, it falls back to the Auto state. In the Auto state:

  • when the <dialog> is opened with showModal(), it behaves as if: closedby="closerequest"
  • when the <dialog> is opened by any other means, it behaves as if: closedby="none"

Examples

Basic 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>
<button id="open">Open modal</button>
const logElement = document.getElementById("log");
function log(text) {
  logElement.innerText = `${logElement.innerText}${text}\n`;
  logElement.scrollTop = logElement.scrollHeight;
}
const button = document.getElementById("open");
button.addEventListener("click", () => {
  const dialog = document.querySelector("dialog");
  dialog.showModal();
});
const dialog = document.querySelector("dialog");
log(`closedBy: ${dialog.closedBy}`);

Result

Basic closedBy usage

Specifications

Browser compatibility

See also

  • HTML dialog element

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。