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

window.getSelection() does not work

35 views
Skip to first unread message

MyOwnClone

unread,
Aug 14, 2009, 10:04:55 AM8/14/09
to
Dear newsgroup,
I am dealing with little problem. I am trying to get (from my
extension) user selected text from actual page. I am using recommended
code:

var selection = window.getSelection();

but, when I am trying to convert it using toString() or even print it
using:

alert(selection.toString());

I got only empty popup without any text.
When I tried to use Venkmann to debug this code, I've come to
conclusion that whole selection object I've got is empty (all members
are 0 or null).

Does anybody know how to deal with this?

Thank you for any information.
Tomas Vymazal

Neil

unread,
Aug 14, 2009, 10:32:56 AM8/14/09
to
MyOwnClone wrote:

>I am dealing with little problem. I am trying to get (from my extension) user selected text from actual page. I am using recommended code:
>
>var selection = window.getSelection();
>

That's the browser's window, not the page's window. You probably want
content.getSelection(); see
https://developer.mozilla.org/en/Working_with_windows_in_chrome_code#Content_windows

--
Warning: May contain traces of nuts.

MyOwnClone

unread,
Aug 19, 2009, 1:34:40 PM8/19/09
to
On 14 srp, 16:32, Neil <n...@parkwaycc.co.uk> wrote:
> MyOwnClone wrote:
> >I am dealing with little problem. I am trying to get (from my extension) user selected text from actual page. I am using recommended code:
>
> >var selection = window.getSelection();
>
> That's the browser's window, not the page's window. You probably want
> content.getSelection(); seehttps://developer.mozilla.org/en/Working_with_windows_in_chrome_code#...

>
> --
> Warning: May contain traces of nuts.

Many thanks!
This proved helpful. Now I am using this code to get selected text
from actual page:

var selObj = content.document.getSelection();

Everything works fine. Thank you again,
Tomas Vymazal

0 new messages