title: Is it possible to insert text in textarea and update undo/redo queue?
body: <p>A few days ago, I posted a <a href="https://stackoverflow.com/questions/19708836/replace-text-in-textarea-using-textinput-event">question</a> regarding how to update text in Internet Explorer. As it appears, the method used doesn't also works in Firefox.</p>
  
  <p>This made me thinks if there is a way to modify the value of a textarea and update the undo/redo queue as well (calling <code>ctrl-Z</code> or <code>document.execCommand('undo');</code>)</p>
  
  <p>So far, I have found two possibilities, but they don't work in all the browsers :</p>
  
  <p>Option 1:</p>
  
  <pre><code>var event = document.createEvent('TextEvent');
  event.initTextEvent('textInput', true, true, null, text, 9, "en-US");
  textarea.focus();
  textarea[0].setSelectionRange(selection.start, selection.end);
  textarea[0].dispatchEvent(event);
  </code></pre>
  
  <p>Note: Doesn't seems to work in IE (at all) and Firefox</p>
  
  <p>Option 2 :</p>
  
  <pre><code>document.execCommand("insertText", false, "the text to insert");
  </code></pre>
  
  <p>Doesn't work in IE (tested under 9, but seems to not be implemented at all), I don't know for the others browsers.</p>