bgmCoder
bgmCoder

Reputation: 6371

How to get currently selected text from Thunderbird Message Composer

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.

Upvotes: 2

Views: 404

Answers (2)

Valerij
Valerij

Reputation: 79

Another way (not so magic as commandDispatcher):

var editor = document.getElementById("content-frame");
var edocument = editor.contentDocument;
var sel = edocument.getSelection();

Upvotes: 0

bgmCoder
bgmCoder

Reputation: 6371

Ah, found it:

var thisselection = document.commandDispatcher.focusedWindow.getSelection();
var thistext = thisselection.toString();
alert(thistext);

Upvotes: 1

Related Questions