In Thunderbird's message composer, I need to use javascript to see if the user has selected any text, and optionally get that selected text.
I tried this:
var thisselection = window.getSelection();
alert("selection = " + thisselection.toString() );
But even if text is selected, it says nothing is selected. I am sure I don't understand what is going on. I was reading from MDN.
I've also tried:
var editor = gMsgCompose.editor;
var thisselection = editor.getSelection.toString();
but then I get an error saying getSelection
is not a function to be used with editor
.
Ah, found it:
var thisselection = document.commandDispatcher.focusedWindow.getSelection();
var thistext = thisselection.toString();
alert(thistext);