title: Insert Text Into Textarea Where Cursor Is
body: <p>I have the following JS that inserts some content into a textarea at the end of whatever is in the textarea currently. This all works fine with the following code:</p>
  
  <pre><code>&lt;script&gt;
  if (opener.document.post.sMessage.createTextRange &amp;&amp; opener.document.post.sMessage.caretPos) {
    var caretPos = opener.document.post.sMessage.caretPos;
    caretPos.text = '\n\n![](http://example.com/image.png)';
  } else {
  opener.document.post.sMessage.value += '\n\n![](http://example.com/image.png)';
  }
  self.close(); //close popup
  &lt;/script&gt;
  </code></pre>
  
  <p>How can this be modified to insert the content into the textarea where the cursor was in the textarea (instead of just at the end of the existing text)?</p>