[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/de/docs/Web/API/Document/queryCommandState [Back]  [Original]

Dokument: queryCommandState()-Methode - Web-APIs | MDN

Dieser Inhalt wurde automatisch aus dem Englischen bersetzt, und kann Fehler enthalten. Erfahre mehr ber dieses Experiment.

View in English Always switch to English

Dokument: queryCommandState()-Methode

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 oder contenteditable.

Nicht standardisiert: Diese Funktion ist nicht standardisiert. Wir raten davon ab, nicht-standardisierte Funktionen auf produktiven Webseiten zu verwenden, da sie nur von bestimmten Browsern untersttzt werden und sich in Zukunft ndern oder entfernt werden knnen. Unter Umstnden kann sie jedoch eine geeignete Option sein, wenn es keine standardisierte Alternative gibt.

Hinweis: Obwohl die Methode execCommand() veraltet ist, gibt es immer noch einige gltige Anwendungsflle, fr die es noch keine brauchbaren Alternativen gibt, wie im Artikel zu execCommand() erwhnt. In diesen Fllen kann sich diese Methode als ntzlich erweisen, um ein vollstndiges Benutzererlebnis zu implementieren, aber testen Sie, um eine plattformbergreifende Browser-Kompatibilitt sicherzustellen.

Die queryCommandState()-Methode informiert Sie darber, ob die aktuelle Auswahl einen bestimmten Document.execCommand()-Befehl angewendet hat.

In diesem Artikel

Syntax

js
queryCommandState(command)

Parameter

command

Ein Befehl von Document.execCommand()

Rckgabewert

queryCommandState() kann einen booleschen Wert oder null zurckgeben, wenn der Status unbekannt ist.

Beispiel

HTML

html
<div contenteditable="true">Select a part of this text!</div>
<button>Test the state of the 'bold' command</button>
<hr />
<div id="output"></div>

JavaScript

js
function makeBold() {
  const state = document.queryCommandState("bold");
  let message;
  switch (state) {
    case true:
      message = "The bold formatting will be removed from the selected text.";
      break;
    case false:
      message = "The selected text will be displayed in bold.";
      break;
    default:
      message = "The state of the 'bold' command is indeterminable.";
      break;
  }
  document.querySelector("#output").textContent = `Output: ${message}`;
  document.execCommand("bold");
}

document.querySelector("button").addEventListener("click", makeBold);

Ergebnis

Spezifikationen

Dieses Merkmal ist Teil keiner aktuellen Spezifikation. Es ist nicht mehr auf dem Weg, ein Standard zu werden. Es gibt einen inoffiziellen W3C execCommand Spezifikationsentwurf.

Browser-Kompatibilitt

Siehe auch


Web Proxy Viewer  |  New URL  |  Original Page