window.getSelection() does not work - Mozilla

This is a discussion on window.getSelection() does not work - Mozilla ; 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 ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: window.getSelection() does not work

  1. window.getSelection() does not work

    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

  2. Re: window.getSelection() does not work

    On 14 srp, 16:32, Neil 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

+ Reply to Thread