Javascript textarea undo redo

If the textarea has focus and its caret is at the correct position,

document.execCommand("insertText", false, "the text to insert");

will insert the text “the text to insert”, preserving the browser’s native undo stack. (See the work in progress HTML Editing API spec.) Chrome 18 supports this, but I’m unsure of the exact version it was introduced.

Leave a Comment