Skip to content

Commit 22cf84f

Browse files
younisdevJosh-Cenalionel-rowegithub-actions[bot]
authored
Clarify execCommand valid use cases without alternatives. (mdn#40263)
* Clarify `execCommand` valid use cases without alternatives. * Fix some inconsistency * Update index.md * Update files/en-us/web/api/document/execcommand/index.md Co-authored-by: lionel-rowe <lionel.rowe@gmail.com> * Propagate note * Update files/en-us/web/api/document/execcommand/index.md Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --------- Co-authored-by: Joshua Chen <sidachen2003@gmail.com> Co-authored-by: lionel-rowe <lionel.rowe@gmail.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 19bf2ac commit 22cf84f

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

files/en-us/web/api/document/execcommand/index.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ browser-compat: api.Document.execCommand
1010

1111
{{ApiRef("DOM")}}{{deprecated_header}}
1212

13+
> [!NOTE]
14+
> Although the `execCommand()` method is deprecated, there are still some valid use cases that do not yet have viable alternatives. For example, unlike direct DOM manipulation, modifications performed by `execCommand()` preserve the undo buffer (edit history). For these use cases, you can still use this method, but test to ensure cross-browser compatibility, such as by using {{domxref("document.queryCommandSupported()")}}.
15+
1316
The **`execCommand`** method implements multiple different commands. Some of them provide access to the clipboard, while others are for editing [form inputs](/en-US/docs/Web/HTML/Reference/Elements/input), [`contenteditable`](/en-US/docs/Web/HTML/Reference/Global_attributes/contenteditable) elements or entire documents (when switched to [design mode](/en-US/docs/Web/API/Document/designMode)).
1417

15-
To access the clipboard, the newer [Clipboard API](/en-US/docs/Web/API/Clipboard_API) is recommended over `execCommand()`. However, there is no replacement for the editing commands: unlike direct DOM manipulation, modifications performed by `execCommand()` preserve the undo buffer (edit history).
18+
To access the clipboard, the newer [Clipboard API](/en-US/docs/Web/API/Clipboard_API) is recommended over `execCommand()`.
1619

1720
Most commands affect the document's [selection](/en-US/docs/Web/API/Selection). For example, some commands (bold, italics, etc.) format the currently selected text, while others delete the selection, insert new elements (replacing the selection) or affect an entire line (indenting). Only the currently active editable element can be modified, but some commands (e.g., `copy`) can work without an editable element.
1821

@@ -218,7 +221,7 @@ function insertText(newText, selector) {
218221

219222
## Specifications
220223

221-
{{Specifications}}
224+
This feature is not part of any current specification. It is no longer on track to become a standard. There is an unofficial [W3C execCommand spec draft](https://w3c.github.io/editing/docs/execCommand/).
222225

223226
## Browser compatibility
224227

@@ -230,3 +233,6 @@ function insertText(newText, selector) {
230233
- MDN example: [execCommands supported in your browser](https://mdn.github.io/dom-examples/execcommand/)
231234
- {{domxref("HTMLElement.contentEditable")}}
232235
- {{domxref("document.designMode")}}
236+
- {{domxref("document.queryCommandEnabled()")}}
237+
- {{domxref("document.queryCommandState()")}}
238+
- {{domxref("document.queryCommandSupported()")}}

files/en-us/web/api/document/querycommandenabled/index.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ browser-compat: api.Document.queryCommandEnabled
1111

1212
{{ApiRef("DOM")}}{{deprecated_header}}{{Non-standard_header}}
1313

14+
> [!NOTE]
15+
> Although the {{domxref("Document/execCommand", "execCommand()")}} method is deprecated, if you do decide to use it for reasons given on that page, you should consider checking the command's availability using `queryCommandEnabled()` to ensure compatibility.
16+
1417
The **`Document.queryCommandEnabled()`** method reports whether
1518
or not the specified editor command is enabled by the browser.
1619

@@ -50,13 +53,13 @@ if (flg) {
5053

5154
## Specifications
5255

53-
This feature is not part of any current specification. It is no longer on track to become a standard.
56+
This feature is not part of any current specification. It is no longer on track to become a standard. There is an unofficial [W3C execCommand spec draft](https://w3c.github.io/editing/docs/execCommand/).
5457

5558
## Browser compatibility
5659

5760
{{Compat}}
5861

5962
## See also
6063

61-
- {{domxref("Document.execCommand()")}}
62-
- {{domxref("Document.queryCommandSupported()")}}
64+
- {{domxref("document.execCommand()")}}
65+
- {{domxref("document.queryCommandSupported()")}}

files/en-us/web/api/document/querycommandstate/index.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ browser-compat: api.Document.queryCommandState
1111

1212
{{ApiRef("DOM")}}{{deprecated_header}}{{Non-standard_header}}
1313

14+
> [!NOTE]
15+
> Although the {{domxref("Document/execCommand", "execCommand()")}} method is deprecated, there are still some valid use cases that do not yet have viable alternatives, as mentioned in the `execCommand()` article. In these cases, you may find this method useful to implement a complete user experience, but test to ensure cross-browser compatibility.
16+
1417
The **`queryCommandState()`** method will tell you if the current selection has a certain {{domxref("Document.execCommand()")}} command applied.
1518

1619
## Syntax
@@ -76,7 +79,7 @@ document.querySelector("button").addEventListener("click", makeBold);
7679

7780
## Specifications
7881

79-
This feature is not part of any current specification. It is no longer on track to become a standard.
82+
This feature is not part of any current specification. It is no longer on track to become a standard. There is an unofficial [W3C execCommand spec draft](https://w3c.github.io/editing/docs/execCommand/).
8083

8184
## Browser compatibility
8285

@@ -86,4 +89,5 @@ This feature is not part of any current specification. It is no longer on track
8689

8790
- {{domxref("HTMLElement.contentEditable")}}
8891
- {{domxref("document.designMode")}}
92+
- {{domxref("document.execCommand()")}}
8993
- Browser bugs related to `queryCommandState()`: [Scribe's "Browser Inconsistencies" documentation](https://github.com/guardian/scribe/blob/master/BROWSERINCONSISTENCIES.md#documentquerycommandstate)

files/en-us/web/api/document/querycommandsupported/index.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ browser-compat: api.Document.queryCommandSupported
1111

1212
{{ApiRef("DOM")}}{{deprecated_header}}{{Non-standard_header}}
1313

14+
> [!NOTE]
15+
> Although the {{domxref("Document/execCommand", "execCommand()")}} method is deprecated, if you do decide to use it for reasons given on that page, you should consider checking the command's availability using `queryCommandSupported()` to ensure compatibility.
16+
1417
The **`Document.queryCommandSupported()`** method reports
1518
whether or not the specified editor command is supported by the browser.
1619

@@ -48,13 +51,13 @@ if (flg) {
4851

4952
## Specifications
5053

51-
This feature is not part of any current specification. It is no longer on track to become a standard.
54+
This feature is not part of any current specification. It is no longer on track to become a standard. There is an unofficial [W3C execCommand spec draft](https://w3c.github.io/editing/docs/execCommand/).
5255

5356
## Browser compatibility
5457

5558
{{Compat}}
5659

5760
## See also
5861

59-
- {{domxref("Document.execCommand()")}}
60-
- {{domxref("Document.queryCommandEnabled()")}}
62+
- {{domxref("document.execCommand()")}}
63+
- {{domxref("document.queryCommandEnabled()")}}

0 commit comments

Comments
 (0)