Document.queryCommandSupported()

已弃用: 不再推荐使用该特性。虽然一些浏览器仍然支持它,但也许已从相关的 web 标准中移除,也许正准备移除或出于兼容性而保留。请尽量不要使用该特性,并更新现有的代码;参见本页面底部的兼容性表格以指导你作出决定。请注意,该特性随时可能无法正常工作。

Document.queryCommandSupported() 方法确定浏览器是否支持指定的编辑指令。

语法

isSupported = document.queryCommandSupported(command);
command

待确定是否支持的命令。

如果命令不被支持,将触发 NotSupportedError 异常。

另外:

  • 如果命令没有值或未启用,将返回空字符串。
  • "fontSize" 命令将被特殊处理,如果值被重写,它将返回最近似标准尺寸的整数倍像素大小。
  • 如果命令的值已被重写,将由重写返回。
  • 否则,此命令返回命令的值,如同 document.queryCommandValue().

示例

js
var flg = document.queryCommandSupported("SelectAll");

if (flg) {
  // ...Do something
}

规范

此特性不属于任何规范,也不再有望被标准化。

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
queryCommandSupported
DeprecatedNon-standard

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
Non-standard. Check cross-browser support before using.
Deprecated. Not for use in new websites.
Has more compatibility info.

参见