Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

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

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 17 9.0 (9.0)[1] 4.0 ? ?
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support ? 9.0 (9.0)[1] ? ? ?

[1] Before Firefox 41, queryCommandEnabled() with arguments cut, copy or paste would throw errors unless the script had special privileges.

See also

文档标签和贡献者

 此页面的贡献者: Sebastianz, teoli, hallvors
 最后编辑者: Sebastianz,