This is much easier in IE using What I would suggest is doing the DOM traversal to find all text nodes within the TextRange
, which is based around characters, words and sentences rather than nodes and offsets. In non-IE browsers, you'll need to do tedious manual traversal of text nodes in the DOM. However, even if you were to do this to get the first ten text characters within your innerHTML
, which would try and fail to find "asdf asdfa" (innerHTML
would start with "asdf asdfa", or possibly "asdf as
", depending on browser).
s, thus avoiding Ranges altogether and therefore making this work in all major browsers.