<p>Is there any way to insert a text (string, may or may not have html tags) to a <code>div</code>?</p>
<p>It has to be a <code>div</code> and not a <code>textarea</code>.</p>
<p>First of all, I need to get the cursor position, then insert the text in that position. It's similar to function <code>insertAdjacentText</code>, but it can only insert before or after a tag, and only works in IE.</p>
<p>Refer to this URL: <a href="http://yart.com.au/test/iframe.aspx" rel="nofollow noreferrer">http://yart.com.au/test/iframe.aspx</a>. Note how you can position the cursor in the div, we need to add text at the cursor location.</p>

The Range and Selection Objects
Use the
selection
and
range objects
.  These contain all kinds of information about the current selection, and where it lies within the node tree.
Fair Warning:
It's not entirely impossible to do what you're describing, but if you get very fancy, you'll be in pretty deep water of
browser quirks and incompatibilities
.  You're going to have to do a lot of
object detection
, checking to make sure you've got consistent values and methods. Incrementally check all of your browsers as you develop.  Good luck!