I had a similar problem found in this polyfill, which was very useful for me as I could not use rangy in my situation: http://bl.ocks.org/visnup/3456262
Edit: The original link really ruined. Looking back at my old code, it looks like polyfill never got into the release code, we just went with a function discovery like this:
if(window.getSelection || document.selection){
then on mouseup:
var range; if(window.getSelection){ var selection = window.getSelection(); range = selection.getRangeAt(0); } else if(document.selection){ range = document.selection.createRange(); if(!range.surroundContents){
... and therefore IE8 users are not supported for this feature.
However, all is not lost: there is a newer (than my original answer) polyfill on Github , which can work if you need to support IE8. It looks rather meager and comprehensive.
Coder source share