How can I “undo” the programmatic insertion of text into a textarea?
I have a textarea and a button. Clicking the button causes text to be inserted into the textarea. Is there a way to allow a user to press Ctrl/Cmd+z to undo the insertion of text and revert the textarea to its previous state? I think the easiest approach to leverage browser's undo stack instead of capturing events. To do this you need to use different codes for different browsers. Luckily out of all major browsers only Firefox has a different approach. // http://stackoverflow.com/a/9851769/529024 // Opera 8.0+ var isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator