W3cubDocs

/Web APIs

CommandEvent: command property

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

The command read-only property of the CommandEvent interface returns a string containing the value of the command property at the time the event was dispatched.

Value

A string.

Examples

In the following simple example we've set up an event listener to listen for the "show-modal" command:

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

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

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Opera Safari Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet WebView Android WebView on iOS
command 135 135 preview 120 preview 135 No 89 No No 135 No

See also

© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/CommandEvent/command