Following code will return the selected text.
function getSelectedText(frameId) {
// In ExtJS use:
// var frame = Ext.getDom(frameId);
var frame = document.getElementById(frameId);
var frameWindow = frame && frame.contentWindow;
var frameDocument = frameWindow && frameWindow.document;
if (frameDocument) {
if (frameDocument.getSelection) {
// Most browsers
return String(frameDocument.getSelection());
}
else if (frameDocument.selection) {
// Internet Explorer 8 and below
return frameDocument.selection.createRange().text;
}
else if (frameWindow.getSelection) {
// Safari 3
return String(frameWindow.getSelection());
}
}
/* Fall-through. This could happen if this function is called
on a frame that doesn't exist or that isn't ready yet. */
return '';
}
Hope this will help to someone.