CommandEvent: thuộc tính command

Baseline 2025
Newly available

Since December 2025, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

Thuộc tính chỉ đọc command của giao diện CommandEvent trả về một chuỗi chứa giá trị của thuộc tính command tại thời điểm sự kiện được gửi đi.

Giá trị

Một chuỗi.

Ví dụ

Trong ví dụ đơn giản sau, chúng ta thiết lập một trình lắng nghe sự kiện để lắng nghe lệnh "show-modal":

js
document.body.addEventListener(
  "command",
  (event) => {
    const theAction = event.command;

    if (theAction === "show-modal") {
      console.log("Showing modal dialog");
    }
  },
  { capture: true },
);

Thông số kỹ thuật

Thông số kỹ thuật
HTML
# dom-commandevent-command

Khả năng tương thích với trình duyệt

Xem thêm