For all browsers, I have successfully managed to retrieve the selected data from my editable div except for IE8.
Is there anyone who can assist me with this issue?
This is my current code:
get_selection: function () {
var range;
var bookmark;
var length = this._displayText().length;
if (window.getSelection) {
range = window.getSelection().getRangeAt(0);
if (range.commonAncestorContainer.parentNode == this._display) {
return { start: range.startOffset, end: range.endOffset, text: this._displayText().substr(range.startOffset, range.endOffset - range.startOffset) };
}
}
else if (document.selection) {
//solution for IE8 and lower
}
return { start: 0, end: 0, text: "" };
},
this._display refers to my editable div element. this._displayText() will return the textContent from my display element. I created a separate function for this because textContent is not supported in IE8, where I use innerText instead.
I have already attempted various solutions found online, but none of them were successful in providing me with the start and end position of the caret.