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 compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic supportChrome Full support 17Edge Full support YesFirefox Full support 41
Full support 41
No support 9 — 41
Notes
Notes queryCommandEnabled with arguments cut, copy or paste would throw errors unless the script had special privileges.
IE Full support 4Opera ? Safari ? WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 41
Full support 41
No support 9 — 41
Notes
Notes queryCommandEnabled with arguments cut, copy or paste would throw errors unless the script had special privileges.
Opera Android ? Safari iOS ? Samsung Internet Android ?

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown
See implementation notes.
See implementation notes.

See also

Document Tags and Contributors

Contributors to this page: fscholz, balrobz, mfluehr, erikadoyle, Sebastianz, teoli, hallvors
Last updated by: fscholz,