Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you manipulate selected text via a Firefox extension

I'm working on a Firefox extension that will manipulate highlighted text.

On a stand-alone page, I can get the selected text with:

selectedText = document.selection?document.selection.createRange().text;

Then I'd manipulate the selected text with string operations on the textarea in question. Unfortunately, that isn't possible for a plugin since I don't know where the user's selected text is.

Is there a way get the name of the element in which text is selected or to alter selected text without the name of the element?

like image 622
Mark Wilbur Avatar asked Oct 14 '22 17:10

Mark Wilbur


1 Answers

selectedText = content.getSelection().toString();
like image 96
altblue Avatar answered Oct 18 '22 12:10

altblue