Results 1 to 3 of 3

Thread: Get Selected Text In Text Area In Internet Explorer

  1. #1

    Default Get Selected Text In Text Area In Internet Explorer

    Hi,

    I have a problem here that I can't seem to solve... I took over a 3.x project and there is a custom extension for the HTML Editor for text areas that provided additional functionality for the URL (hyperlink) button...

    In order to execute the additional functionality the extension needs to get the selected text in the text area... It works fine for Firefox, Safari and Chrome but it does not work for IE.

    Here's the current code that gets the text selection:

    win = this.getWin();
    var sel = win.getSelection ? win.getSelection() : win.document.selection;

    IE does not return the text... I have tried these suggested solutions for IE:

    http://www.sencha.com/forum/showthre...election-range

    still no go...

    Can anybody help ?

    Thanks in advance for your help !!!

    - M

  2. #2
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,379

    Default

    This should work on IE:

    Code:
    text = (document.all) ? document.selection.createRange().text : document.getSelection();
    Mitchell Simoens @LikelyMitch

    Check out my GitHub:
    https://github.com/mitchellsimoens

    Posts are my own, not any current, past or future employer's.

  3. #3

    Default

    @mitchellsimoens : thanks for your reply !

    I tried your solution and it does not work for any browser in the Ext JS 3.x project.

    In a standalone simple test text area (plain HTML with an attached JavaScript function) your solution returns the selected text in IE but not in FF, Safari and Chrome...

    Btw, I noticed with my solution up top that on IE the selected text gets un-selected when it processes it and tries to get the text selection... that does not happen in any of the other browsers...

    Could that be the reason why it is returning an empty string ?

    Thanks.

    - M

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •