このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

Document: queryCommandEnabled() メソッド

Deprecated

Avoid using this feature in new projects. The execCommand() method is "not implemented consistently or fully by user agents, and it is not expected that this will change in the foreseeable future." This feature may be a candidate for removal from web standards or browsers.

Consider using the following features instead: Async clipboardまたはcontenteditable.

非標準: この機能は標準化されていません。非標準の機能はブラウザーの対応が限られ、将来的に変更または削除される可能性があるため、本番環境での使用は推奨されません。ただし、標準の選択肢が存在しない特定のケースでは、有効な代替手段となる場合があります。

The Document.queryCommandEnabled() メソッドは、指定したエディターコマンドがブラウザーで有効になっているかどうかを報告します。

構文

js
document.queryCommandEnabled(command)

引数

command

対応するかどうかを判断するコマンド。

返値

論理値で、コマンドが有効な場合は true、無効な場合は false を返します。

メモ

  • 'cut' および 'copy' コマンドの場合、このメソッドはユーザーが起動したスレッドから呼び出されたときのみ true を返します。
  • 'paste' コマンドは、その機能が利用できない場合だけでなく、呼び出されたスクリプトがそのアクションを実行するのに十分な権限を持っていない場合にも false を返します。

js
const flg = document.queryCommandEnabled("SelectAll");

if (flg) {
  document.execCommand("SelectAll", false, null); // コマンドが有効なので、実行する
}

仕様書

この機能はどの現行仕様にも属していません。標準化の予定はなくなりました。

ブラウザーの互換性

関連情報