8
votes

I have a textarea. It has default undo/redo functionality, either with ctrl-z/y or by right-clicking and choosing copy/paste.

I want to create an undo/redo button and trigger the native undo/redo. I'm not sure how to trigger this. (Was surprised that my users don't know ctrl-z)

1
That question contains the answer to my question (use execCommand). But finding that question requires already knowing to search for "execCommand", which is what I didn't know. So I still think it could be worthwhile to have this question here with an answer. But whatever others think... - user984003
possible duplicate, does not mean it is a duplicate per se, it's just a flag for moderators to take a look, and for future people landing here to have an extra link to check out. - NDM

1 Answers

5
votes

You can use document.execCommand to achieve this functionallity. It is used by some HTML-editors.

execCommand compatibility

And by now, this is deprecated, and should not be used.