Here is a small piece of code that I found here , hope this helps:
function setRange(rte) {
var oRTE;
if (document.all) {
oRTE = frames[rte];
var selection = oRTE.document.selection;
if (selection != null) rng = selection.createRange();
} else {
oRTE = document.getElementById(rte).contentWindow;
var selection = oRTE.getSelection();
rng = selection.getRangeAt(selection.rangeCount - 1).cloneRange();
}
return rng;
}
It looks like you can use the attribute selectionfor the document object and then use the method createRange(). if-elseprobably supports cross browser.
source
share