2013-05-12 59 views
2

在Thunderbird的消息編輯器中,我需要使用javascript來查看用戶是否選擇了任何文本,並可以選擇獲取所選文本。如何從Thunderbird Message Composer中獲取當前選定的文本

我嘗試這樣做:

var thisselection = window.getSelection(); 
alert("selection = " + thisselection.toString()); 

但是,即使選擇的文本,它說沒有什麼選擇。我相信我不明白髮生了什麼事。 I was reading from MDN

我也試過:

var editor = gMsgCompose.editor; 
var thisselection = editor.getSelection.toString(); 

但後來我得到一個錯誤說getSelection不能與editor使用的功能。

回答

1

啊,發現:

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

你的答案救了我的天!非常感謝你。 – learningloop 2016-04-21 12:42:49

0

另一種方式(沒有這麼神奇的commandDispatcher):

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