Executes a command on the current document, current selection, or the given range.
Questions tagged [execcommand]
294 questions
246
votes
9 answers
execCommand() is now obsolete, what's the alternative?
I intended to use Document.execCommand() method along with contenteditable attribute to build my custom WYSIWYG editor. But when I checked the documentation for Document.execCommand(), I found that it's now obsolete. What's the modern (or extant)…

Omar
- 6,681
- 5
- 21
- 36
138
votes
13 answers
Javascript trick for 'paste as plain text` in execCommand
I have a basic editor based on execCommand following the sample introduced here. There are three ways to paste text within the execCommand area:
Ctrl+V
Right Click -> Paste
Right Click -> Paste As Plain Text
I want to allow pasting only plain…

Googlebot
- 15,159
- 44
- 133
- 229
32
votes
2 answers
Contenteditable div vs. iframe in making a rich-text/wysiwyg editor
i'm trying to weigh the pros and cons of using a
vs.
25
votes
3 answers
Is there something better than document.execCommand?
When implementing a web-based rich-text editor, I read that document.execCommand is useful for performing operations on an HTML document (like making a selection bold). However, I need something a bit better. Specifically, I need to know exactly…

Brent
- 4,153
- 4
- 30
- 63
24
votes
4 answers
Cannot use `document.execCommand('copy');` from developer console
Calling document.execCommand('copy'); from the Chrome developer console returns false every time.
Give it a try yourself. Open the console and run it, it never succeeds.
Any idea as to why?

Domi
- 22,151
- 15
- 92
- 122
24
votes
2 answers
Is there a way to keep execCommand("insertHTML") from removing attributes in chrome?
Context is Chrome 37.0.2062.120 m.
I'm using execCommand to insert html into an editable div. My execCommand call looks like this:
function insertHTML(){
document.execCommand('insertHTML', false, 'hi');
}
When the…

sonicblis
- 2,926
- 7
- 30
- 48
21
votes
10 answers
document.execCommand() FontSize in pixels?
How can I change font size to 30px (for example) using document.execCommand?
This:
document.execCommand("fontSize", false, "30px");
doesn't work, because in 3rd argument of the function execCommand, it only allows me to input a value between and…

bordeux
- 612
- 1
- 8
- 23
20
votes
6 answers
Adding a target="_blank" with execCommand 'createlink'
I am attempting to create a mini WYSIWYG editor for a custom CMS. It has the option to add and remove links. It adds links fine, but would like to have the option to add target="_blank" to the hyperlink. Also, if possible, I would like to be able to…

thelos999
- 641
- 2
- 7
- 19
20
votes
1 answer
JavaScript document.execCommand() own tags
I've found some really interesting! The execCommand function applies many useful features. But is it possible to work with OWN wraps? Like:
document.execCommand("styleWithCSS", false, "");
Everything related i've found was…

YeppThat'sMe
- 1,812
- 6
- 29
- 45
14
votes
2 answers
Is there a replacement for document.execCommand? (or is it safe to use document.execCommand?)
I am building an amateur rich text editor with vanilla JavaScript and document.execCommand() is essential to enabling the core features of an text editor.
For example bold, italic and unordered list commands:
Array.from(toolbarBtn).forEach(btn =>…

Linas M.
- 312
- 1
- 3
- 17
11
votes
1 answer
Insert text into an existing / external draftjs textfield
I'm working on an application which needs to insert text into a contenteditable="true" div (a Draftjs based textfield to be precise).
Now I am aware that Draft.js uses react and that it should be used that way, but in this case, the application…

JoniVR
- 1,839
- 1
- 22
- 36
10
votes
1 answer
html contentEditable document.execCommand change selected opacity
any one worked with changing opacity on contentEditable selected.
I tried with following:
document.execCommand('foreColor', false, 'rgba(0,0,0,0.5)'); // with rgba
document.execCommand('foreColor', false, '80000000'); // with alpha hex
none worked.…

abduIntegral
- 521
- 4
- 7
- 21
10
votes
3 answers
How does execCommand "insertBrOnReturn" work?
I tried the following code on Chrome:
document.execCommand("insertBrOnReturn", false, true);
http://jsfiddle.net/uVcd5/
Wether I set the last parameter to true or false, the behaviour doesn't change: on return, new
elements will be…

Matthew
- 10,988
- 11
- 54
- 69
9
votes
4 answers
set execcommand just for a div
it has any way for bind execcommand with a div element not for whole document , i try this :
document.getElementById('div').execcommand(...)
but it has an error :
execcommand is not a function
it has any way for bind the execcommand with just div…

mkotwd
- 233
- 2
- 3
- 6
9
votes
2 answers
execCommand('copy') does not work in Ajax / XHR callback?
(Tested using Chrome 44)
Desired behaviour: Make XHR request, put result in text area, select text, and copy to clipboard.
Actual behaviour: On successful XHR request, puts the result in text area and selects it, but fails to copy result to…

aeoliant
- 377
- 2
- 10