Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to get selected text from browser

12 views
Skip to first unread message

mor...@hotmail.com

unread,
Nov 19, 2006, 5:50:15 PM11/19/06
to
Hi,

I'd like to do something pretty basic in a browser extension that
involves getting information that is highlighted - how can I evaluate
what is highlighted in the browser? Thanks for your help with this
basic question.

mark bokil

unread,
Nov 19, 2006, 5:55:40 PM11/19/06
to dev-ext...@lists.mozilla.org

LouCypher

unread,
Nov 20, 2006, 8:54:34 AM11/20/06
to
var focusedWindow = document.commandDispatcher.focusedWindow;
var winWrapper = new XPCNativeWrapper(focusedWindow, "document",
"getSelection()");
var string = winWrapper.getSelection().toString();

Soyapi Mumba

unread,
Nov 21, 2006, 3:47:31 AM11/21/06
to LouCypher, dev-ext...@lists.mozilla.org
LouCypher wrote:
> var focusedWindow = document.commandDispatcher.focusedWindow;
> var winWrapper = new XPCNativeWrapper(focusedWindow, "document",
> "getSelection()");

document.getSelection() is deprecated. For the line above, use:

var winWrapper = new XPCNativeWrapper(focusedWindow, "window", "getSelection()");

> var string = winWrapper.getSelection().toString();

--
Soyapi Mumba
soyapi.blogspot.com

Matthew Smith

unread,
Nov 28, 2006, 12:22:48 AM11/28/06
to dev-ext...@lists.mozilla.org
A recent thread talked about working with selected text:

I have just been trying to implement this in Firefox 2. If I have a
button on my toolbar that calls this:

selObj = window.getSelection();
window.alert(selObj);

I just get an empty alert. (This is copied straight from the MDC page
Dom:selection.)

I have looked through DomInspector to see if there is another window
object that I should be using, but using other window objects that I
found like this:

document.getElementById('content').selectedBrowser.focusedWindow.getSelection()

...doesn't work either.

Can anyone tell me how to do this in Firefox?

Cheers

M


--
Matthew Smith
IT Consultancy & Web Application Development
Business: http://www.kbc.net.au/
Personal: http://www.smiffysplace.com/
LinkedIn: http://www.linkedin.com/in/smiffy

Neil

unread,
Nov 29, 2006, 5:09:03 AM11/29/06
to
Matthew Smith wrote:

>A recent thread talked about working with selected text:
>
>>>I'd like to do something pretty basic in a browser extension that involves getting information that is highlighted - how can I evaluate what is highlighted in the browser? Thanks for your help with this basic question.
>>>
>>>
>>See window.getSelection here:
>>http://developer.mozilla.org/en/docs/DOM:window.getSelection
>>
>>
>I have just been trying to implement this in Firefox 2. If I have a button on my toolbar that calls this:
>
>selObj = window.getSelection();
>window.alert(selObj);
>
>I just get an empty alert.
>

content.getSelection() probably suffices in your case.

--
Warning: May contain traces of nuts.

0 new messages