title: Inserting text into an editable IFRAME at the caret position (IE)
body: <p>I'm struggling with an actually straighforward problem: In Internet Explorer I want to insert plain text at the current caret position. This works really fine for simple TEXTAREA elements but it doesn't entirely work for editable IFRAMEs, which is what I have. </p>
  
  <p>In the script I use I am creating a TextRange object from the document of the IFRAME which I use to paste the text as HTML at the cursor position.</p>
  
  <pre><code>&lt;iframe id="editable"&gt;
    &lt;html&gt;
      &lt;body&gt;
        Some really boring text.
      &lt;/body&gt;
    &lt;/html&gt;
  &lt;/iframe&gt;
  &lt;script type="text/javascript"&gt;
  
      window.onload = function() {
          var iframe = document.getElementById('editable');
          var doc = iframe.contentDocument || iframe.contentWindow.document;
  
          doc.body.innerHTML = iframe.textContent || iframe.innerHTML;
  
          // Make IFRAME editable
          if (doc.body.contentEditable) {
              doc.body.contentEditable = true;
          } 
      }
  
      function insert(text) {
          var iframe = document.getElementById('editable');
          var doc = iframe.contentDocument || iframe.contentWindow.document;
          iframe.focus();
        if(typeof doc.selection != 'undefined') {
              var range = doc.selection.createRange();
              range.pasteHTML(text);
        }
  }
  &lt;/script&gt;
  &lt;input type="button" value="Insert" onClick="insert('foo');"/&gt;
  </code></pre>
  
  <p>When I select some text in the IFRAME, the selection will be replaced with "foo" - this is expected behaviour. But when I just place the caret somewhere in the text, the insertion won't work.</p>
  
  <p>Is this common behaviour, as there is "no real selection" for the case that I just place the cursor somewhere or is it a bug with editable IFRAMEs in IE, since it works pretty well with simple TEXTAREA elements?</p>
  
  <p>Is there a workaround?</p>