W3cubDocs

/DOM

document.queryCommandEnabled

The Document.queryCommandEnabled() method reports whether or not the specified editor command is enabled by the browser.

Syntax

isEnabled = document.queryCommandEnabled(command);

Parameters

command
The command for which to determine support.

Return value

Returns a Boolean which is true if the command is enabled and false if the command isn't.

Notes

  • For 'cut' and 'copy' commands the method only returns true when called from a user-initiated thread.
  • The 'paste' command return false not only if the feature is unavailable, but also if the script calling it has insufficient privileges to perform the action.

Example

var flg = document.queryCommandEnabled("SelectAll");

if(flg) {
  document.execCommand("SelectAll", false, null); // command is enabled, run it
}

Specifications

Specification Status Comment
HTML Editing APIs
The definition of 'querycommandenabled' in that specification.
Editor's Draft Initial definition

Browser compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Basic support 17 Yes 41
41
9 — 41
queryCommandEnabled with arguments cut, copy or paste would throw errors unless the script had special privileges.
4 ? ?
Mobile
Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android iOS Safari Samsung Internet
Basic support Yes Yes Yes 41
41
9 — 41
queryCommandEnabled with arguments cut, copy or paste would throw errors unless the script had special privileges.
? ? ?

See also

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/document/queryCommandEnabled