I am working on a simple Firefox Extension and I want to get the selected text. I tried this:
var WordCount = {
/* ... */
changeSelected: function() {
var selectedText = this.getSelection();
var words = this.countWords(selectedText);
this.changeStatus(words, " selected");
//alert(selectedText);
},
getSelection: function(e) {
var focused_window = document.commandDispatcher.focusedWindow;
var sel_text = focused_window.getSelection();
return sel_text.toString();
}
}
window.addEventListener("select", function(e) { WordCount.changeSelected(); }, false);
The Problem is, that I dont get the selection with document.commandDispatcher.focusedWindow.getSelection() and I don't know why :(