dhtmlxEditor - Selected Text

Recently I had the need to get hold of the selected text within my dhtmlxEditor control.

I couldn’t find an API function to do this so wrote my own.

It works in IE and FF (and possibly other browsers as well but can’t verify).

I had to modify my local version of dhtmlxEditor.js file so would be good to make the next version of the product if deemed ok.

this.getSelectedText = function(){

var userSelection = “”;

if (this.edWin.getSelection)


userSelection = this.edWin.getSelection();


else if (this.edDoc.selection)


// should come last; Opera!

userSelection = this.edDoc.selection.createRange();


var selectedText = userSelection;

if (_isIE)


selectedText = userSelection.text;


return selectedText;


Thank you for the provided solution.

Probably we will add this method into the next editor edition.